Showing posts with label Operators. Show all posts
Showing posts with label Operators. Show all posts

Wednesday, 25 July 2018

  Question: Aayush's Scholarship
 
Aayush studies in Teswan National University. Now is the time for exam results. Aayush similar to other students, hopes that his scores in 5 subjects in the exam could fetch him a scholarship for his GRE preparation.

The following simple rules  are used to find whether he is eligible to receive scholarship:

  • University follows 5 point grading system. In an exam, a student can receive any score from 2 to 5.  2 is called an F grade, meaning that student has failed that exam.
  • Student should not have fail any of the exams.
  • Student must obtain a full score in some of his/her exams to show that he/she is excellent in some of the subjects.
  • He/She must have a grade point average not less than 4.0
​You are given information regarding how Aayush performed in those 5 subjects . Help him determine whether he will receive the scholarship or not.

Input Format:
The input contains 5 space separated integers denoting Aayush’s 5 subjects score in the exam.

Output Format:
Output a single line - "Yes" (without quotes) if Aayush will receive scholarship, or "No" (without quotes) otherwise.
Refer sample input and output for formatting specifications.

Sample Input 1:
3 5 4 4 3

Sample Output 1:
No

Sample Input 2:
3 4 4 4 5

Sample Output 2:
Yes


Solution:
 #include<stdio.h>
int main()
{
    int a,b,c,d,e;
    scanf("%d%d%d%d%d",&a,&b,&c,&d,&e);
    if(a==5||b==5||c==5||d==5||e==5)
    {
        if(a==2||b==2||c==2||d==2||e==2)
        printf("NO");
        else if((a+b+c+d+e)/5.0>=4.0)
        printf("Yes");
        else
        printf("No");
    }
    else
    printf("No");
    return 0;
}
Question: Pranav and Change
 
Pranav, an enthusiastic kid visited the "Fun Fair 2017" along with his family. His father wanted him to purchase entry tickets from the counter for his family members. Being a little kid, he is just learning to understand about units of money. Pranav has paid some amount of money for the tickets but he wants your help to give him back the change of Rs. N using minimum number of rupee notes.

Consider a currency system in which there are notes of seven denominations, namely, Rs. 1, Rs. 2, Rs. 5, Rs. 10, Rs. 50, Rs. 100. If the change given to Pranav Rs. N is input, write a program to computer smallest number of notes that will combine to give Rs. N.


Note:
Refer to problem specifications.

Input Format:
First line of the input is an integer N, the change to be given to Pranav.

Output Format:
Output should display the the smallest number of notes that will combine to give N.
Refer sample input and output for formatting specifications.

Sample Input 1:
1200

Sample Output1:
12

Sample Input 2:
242

Sample Output2:
7


Solution:
 #include<stdio.h>
int main()
{
    int n,n1,n2,n3,n4,n5,n6;
    scanf("%d",&n);
    n1=n/100;   n=n%100;
    n2=n/50;    n=n%50;
    n3=n/10;    n=n%10;
    n4=n/5;     n=n%5;
    n5=n/2;     n=n%2;
    n6=n;
    printf("%d",n1+n2+n3+n4+n5+n6);
    return 0;
}
Question: Tile Game
In connection to the National Mathematics Day celebration, the Regional Mathematical Scholars Society had arranged for a Mathematics Challenge Event where school kids participated in large number. Many interesting math games were conducted, one such game that attracted most kids was the tile game where the kids were given 'n' square tiles of the same size and were asked to form the largest possible square using those tiles.

Help the kids by writing a program to find the area of the largest possible square that can be formed, given the side of a square tile (in cms) and the number of square tiles available.

Input Format:
First line of the input is an integer that corresponds to the side of a square tile (in cms).
Second line of the input is an integer that corresponds to the number of square tiles available.

Output Format:
Output should display the area of the largest possible square that can be formed (in square cms) with the available tiles.
Refer sample input and output for formatting specifications.
[All text in bold corresponds to input and rest corresponds to output.]

Sample Input and Output :
Enter the side in cm of a square tile
5
Enter the number of square tiles available
8
Area of the largest possible square is 100sqcm



SOLUTION:
#include<stdio.h>
int main()
{
    int l,n,i=1,m=0,a;
    printf("Enter the side in cm of a square tile");
    scanf("%d",&l);
    printf("\nEnter the number of square tiles available");
    scanf("%d",&n);
    while(i*i <= n)
    {
        m=i*i;
        i++;
    }
    a=m*(l*l);
    printf("\nArea of the largest possible square is %dsqcm",a);
    return 0;
}
Question: Lucky Gifts

"Planet Kids Entertainment Fair" is back to delight kids and parents. The Fair will have non-stop entertainment with an extravaganza of games, exciting rides, sports, art & crafts, role-plays, inspiring competitions, prizes & gifts, and yummy food.

Few lucky attendees at the Fair will be given a pack of candies as a lucky gift and the show coordinator has assigned you the task for choosing the number of attendees who will receive the pack of candies. There are 'N' candies available and you need to decide how many candies to place in each pack. Each pack must contain the same number of candies. You should choose an integer A between 1 and N, inclusive, and place exactly A candies into each pack. You should make as many packs as possible but since you enjoy eating candies very much, you eat the remaining candies.

Write a program that will calculate the maximum number of candies per pack that can be made with 'N' candies so that you can also maximise the number of  candies that you can eat.


Input Format:
The first and only line of input contains an integer N.

Output Format:
Output a single line that gives the maximum number of candy packs that can be made with 'N' candies.
Refer sample input and output for formatting specifications.


Sample Input 1:
2

Sample Output 1:
2

Sample Input 2:
5

Sample Output 2:
3


SOLUTION: 
#include<stdio.h>
int main()
{
    int a,b;
    scanf("%d",&a);
    b=(a/2)+1;
    printf("%d",b);
    return 0;
}
Question: Ticket sold for Charity Event
 
HelpIndia, a famous NGO has been selective in identifying events to raise funds for charity. Suzanne is a volunteer from the NGO who was selling tickets to the public for the charity event. She sold 'X' more adult tickets than children tickets and she sold twice as many senior tickets as children tickets. Assume that an adult ticket costs $5, children ticket costs $2 and senior ticket costs $3.
Suzanne made 'Y' dollars from ticket sales. Find the number of adult tickets, children tickets and senior tickets.

Input Format:
First input is an integer value X that corresponds to the number of adult tickets more than children tickets.
Second input is an integer value Y that corresponds to the money in dollars made by Suzanne from ticket sales.

Output Format:
First line of the output should display the number of children tickets sold.
Second line of the output should display the number of adult tickets sold.
Third line of the output should display the number of senior tickets sold.
Refer sample input and output for formatting specifications.
[All text in bold corresponds to input and rest corresponds to output.]

Sample Input and Output :
Enter the value of X
10
Enter the value of Y
700
Number of children tickets sold : 50
Number of adult tickets sold : 60
Number of senior tickets sold : 100


SOLUTION:
 #include<stdio.h>
int main()
{
    int x,y;
    int b,a,s;
    printf("Enter the value of X");
    scanf("%d",&x);
    printf("\nEnter the value of Y");
    scanf("%d",&y);
    b=(y-(5*x))/13;
    a=x+b;
    s=2*b;
    printf("\nNumber of children tickets sold : %d",b);
    printf("\nNumber of adult tickets sold : %d",a);
    printf("\nNumber of senior tickets sold : %d",s);
    return 0;
}
Question: Talent Show
Mountain View Middle School is all set for organizing their elaborate talent show event of the year, "Stars Onstage". It is a fun-filled event for the students to showcase and build their confidence.

Of the total audience who had come for the show, 1/3 were boys, 3/6 were girls and the rest of them were adults. If there were 'x' more girls than adults, how many people were there in total? Help the School authorities to find the total people who visited their show.


Input Format:
First line of the input is an integer 'x', which corresponds to the count of girls more than adults.

Output Format:
Output the total number of people who had visited the talent show.
Refer sample input and output for formatting specifications.
[All text in bold corresponds to input and rest corresponds to output.]

Sample Input and Output1:
Enter x
50
150 people were there in total

Sample Input and Output2:
Enter x
70
210 people were there in total

Solution:

 #include<stdio.h>
int main()
{
    int x,t,b,g,a;
    printf("Enter x");
    scanf("%d",&x); 
    b=x;
    g=(3*x)/2;
    a=x/2;
    t=b+g+a;
    printf("\n%d people were there in total",t);
    return 0;
}

Random password generator in Java

       Random password generator in Java Source code: mport java.io.*; import java.util.*; public class Main { public static void main(Str...