Posts

Showing posts with the label FLOW CONTROL AND OPERATORS

Laasya looking at the friends birthday list on a social media site likes to find if the particular person's birthday year is a leap year or not. Since many will have the same doubt she decides to automate the task by writing the code snippet for finding the same but she don't know the logic to write it. Can you help Laasya to accomplish her task?

 #include <stdio.h> int main() {    int year;    scanf("%d", &year);    if (year % 400 == 0)printf("LEAP YEAR");    else if (year % 100 == 0) printf("NOT A LEAP YEAR");    else if (year % 4 == 0)printf("LEAP YEAR");    else printf("NOT A LEAP YEAR");    return 0; }

Agathiyan is the Chief In charge for carrying out World Economic Survey in India.As a part of survey his team have collected the salaries of the citizens of India. The Salaries of different people are in different number of digits.Now Agathiyan would like to classify the earnings of the citizen based on the number of digits of his/her salary into 5 different categories as follows:

#include<stdio.h> #include<stdio.h> int main() {int N; scanf("%d",&N); if(N<10) printf("Insufficient Earning"); else if (N<100) printf("Very Low Earning"); else if (N<1000) printf("Low Earning"); else if (N<10000) printf("Sufficient Earning"); else printf("High Earning"); return 0; } 

Given is an integer N.Simon chooses an integer 'a' from the positive integers not greater than 'N' with equal probability. Find the probability that 'a' is odd.

 #include <stdio.h> int main() {int n; float t; scanf ("%d",&n); if(n%2==0) printf("%d",(n/2)/n); else{     t=(n/2);     t=(t+1)/n;     printf("%.9f",t);}               return 0;}

There are two monkeys on an x-axis ready to jump in the positive direction (i.e, toward positive infinity).The first monkey starts at location x1 and moves at a rate of v1 meters per jump. The second monkey starts at location x2 and moves at a rate of v2 meters per jump. Given the starting locations and movement rates for each monkey, can you determine if they'll ever land at the same location at the same time?

 #include<stdio.h> int main() {int x1,x2,v1,v2; scanf("%d %d %d %d",&x1,&v1,&x2,&v2); int m=x1,n=x2; if (v2>v1){printf("NO");} else {for (int i=0;i<10000;i++){m=m+v1;         n=n+v2;         if(m==n){printf("YES"); break;}}     if(m!=n)printf("NO"); } return 0; }

Rohit has 'A' Chocolates and Mohit has 'B' Chocolates. Rohit will do the following action 'K' times.If Rohit has one or more Chocolates, eat one of his Chocolates.Otherwise, if Mohit has one or more Chocolates, eat one of Mohit's Chocolates.If they both have no Chocolates, do nothing.

#include<stdio.h> int main() {int A,B,K; scanf("%d %d %d",&A,&B,&K); if(A>=K) printf("%d %d",(A-K),B); else if (A<=K) printf("%d %d",0,B-(K-A)); return 0;}

Arulmozhivarman is working in ship. He is responsible for classifying the ship into different classes based on the letterclass ID of the ship.Since Arulmozhivarman is working on the same task over the long period of time he is bored of doing the same work again and again.He will enjoy his time in the ship if has a automated script that can classify the ships into different classes if the letterclass id of the ship is provided.Can you help Arulmozhivarman?

 #include <stdio.h> int main() {   char ID;     scanf("%c",&ID);     if((ID=='B')||(ID=='b'))      printf("BattleShip");     else if((ID=='C')||(ID=='c'))      printf("Cruiser");     else if((ID=='D')||(ID=='d'))      printf("Destroyer");     else      printf("Frigate"); return 0;}

Britta's parents said they will buy her a puppy on a 2nd week of a month.They selected a puppy but the vet said it will be delivered only based on the token given to them.The token was printed from 1-7 in number representing days of the week.Britta is very eager and needs to Know the Day on providing the week number [1-7].

 #include <stdio.h> int main() {     int day;     scanf("%d",&day);     if(day==1){printf("Monday");}     else if(day==2){printf("Tuesday");}      else if(day==3){printf("Wednesday");}     else if(day==4){printf("Thursday");}     else if(day==5){printf("Friday"); }     else if(day==6){printf("Saturday");}     else if(day==7){printf("Sunday");  }     else{ printf("Invalid Input");} return 0; }

Caleb and Irfan are purchasing apples which were priced according to their size.But their budget is minimum.So they plan to choose one small, one medium and one large apple so that it will fit in their budget.So can you help them choose the right apple by creating a logic by naming three apples they choose as apple1,apple2,apple3. Then check the condition if apple2 is greater than apple1 and apple3 is greater than apple2.

#include <stdio.h> int main() {     int apple1,apple2,apple3;     scanf("%d\n%d\n%d",&apple1,&apple2,&apple3);     if(apple2>apple1)     {  if(apple3>apple2)        { printf("Fit into Budget");        }else printf("Dosen't fit into Budget");     }     else     {  printf("Dosen't fit into Budget");     } return 0; }

Arav and Aaron are participating in the Bike racing. Arav have crossed some milestores earlier and Aaron crossed some milestores earlier during their racing,because they have changed their speeds at different times.Both of them like to know the difference in speeds between them at different stages of racing.Can you help finding the speed difference between Arav and Aaron?

 #include <stdio.h> int main() {     int aravspeed,aaronspeed,speeddiff;     scanf("%d%d",&aravspeed,&aaronspeed);     if(aravspeed>aaronspeed)     {  speeddiff=aravspeed-aaronspeed;        printf("%d",speeddiff);     }     else     {   speeddiff=aaronspeed-aravspeed;        printf("%d",speeddiff);     }    return 0; }

Fazil frequently uses Hexadecimal notation in his work.In hexadecimal notation, besides the ten digits 0, 1, …9 the six letters A, B, C, D, E and F are used to represent the values 10, 11, 12, 13, 14, …15 respectively.In this problem, you are given two letters X and Y.When X and Y are seen as hexadecimal numbers, which is larger?

 #include <stdio.h> int main() {char X,Y; scanf("%c %c",&X,&Y); if (X<Y){     printf("<"); }else if(X>Y){     printf(">"); }else if(X==Y){     printf("="); }return 0;}

Swathi is working in a world famous pizza restaurant.Her manager ordered her to verify the size of the pizza such that it slices forms an exact triangle.She was given 3 values representing three angles of the slices cut down by chefs and she has to find out whether the slice is Valid or Not.Can you help her in finding it?

 #include <stdio.h> int main() {int angle1,angle2,angle3; scanf("%d %d %d",&angle1,&angle2,&angle3); int sum=angle3+angle2+angle1; if(sum==180){     printf("Pizza Slice is Valid"); }else{     printf("Pizza Slice is Not Valid");} return 0; }

Vikram has just started Programming, he is in first year of Engineering. Vikram is reading about Relational Operators.Relational Operators are operators which check relationship between two values.Given two numerical values A and B you need to help Vikram in finding the relationship between them that is,First one is greater than second or,First one is less than second or,First and second one are equal.

 #include <stdio.h> int main() {int number1,number2; scanf("%d %d",&number1,&number2); if(number1<number2) printf("<"); else if(number1>number2) printf(">"); else printf("="); return 0;}

While purchasing certain items, a discount of 10% is offered by the popular super market if the quantity purchased is more than 1000.Since number of people purchasing is increasing day by day the owner of the super market feels that the discount calculation will be better if there is a automated software that gives the total expenses If the quantity and price per item are input.

 #include <stdio.h> int main() {int price,quantity,totexp; scanf("%d %d",&quantity,&price); if(quantity>=1000){     totexp=0.9*price*quantity;     printf("%d",totexp);} else{     totexp=price*quantity;     printf("%d",totexp); }return 0;}

Anegan is a member of a programming competition site, Awesome Coder.Each member of the Awesome Coder is assigned two values: Inner Rating and Displayed Rating.The Displayed Rating of a member is equal to their Inner Rating if the member has participated in 10 or more contests.Otherwise, the Displayed Rating will be their Inner Rating minus 100 × (10−K) when the member has participated in K contests.Anegan has participated in N contests, and his Displayed Rating is R. Find his Inner Rating.

 #include<stdio.h> int main() {int n,r,ir; scanf("%d %d",&n,&r); if(n>=10){printf("%d",r);} else{     ir=r+100*(10-n);     printf("%d",ir);} return 0;}

The window of Vinod's room has a width of 'A'. There are two screens hung over the window, each of which has a horizontal length of 'B'. (Vertically, the screens are long enough to cover the whole window.)We will close the window so as to minimize the total horizontal length of the uncovered part of the window. Find the total horizontal length of the uncovered parts of the window then.

 #include <stdio.h> int main() {int A,B; scanf("%d %d",&A,&B); if(2*B<A){printf("%d",A-2*B);} else{printf("%d",0);} return 0;}

Selvan is working as a QC in a reputed Multinational Conglmerate. His task is to check if the given Keyboard has a valid alphabets. But since many Keyboards are need to be verified, he is finding is difficult to finish the task.

 #include <stdio.h> int main() {char ch; scanf("%c",&ch); if((ch>='a' && ch<='z') || (ch>='A' && ch<='Z')){printf("ALPHABET");} else{printf("NOT AN ALPHABET");} return 0; }

Yasir a techie working in a military camp was checking the landmine as per their sequence of numbers.Whatever the number the major gives yasir has to : Check if (number < 0), then need to print as negative. Check if(number > 0), then need to print as positive. But Major Simon imposes a strict constraint that he should use If else concept to complete the task. Since he doesn't know the if else concept he is frustrated. Can you help him to complete his task?

 #include <stdio.h> int main() {int number; scanf("%d",&number); if(number<0){ printf("NEGATIVE");} else{printf("POSITIVE");} return 0;}

Johit has two rectangles. The lengths of the vertical sides of the first rectangle are ‘A’ and the lengths of the horizontal sides of the first rectangle are ‘B’ The lengths of the vertical sides of the second rectangle are ‘C’ and the lengths of the horizontal sides of the second rectangle are ‘D’.Johit would like to know the area of the rectangel with the larger area. Can you help him finding it?

 #include <stdio.h> int main() {int a,b,c,d; scanf("%d %d %d %d",&a,&b,&c,&d); if(a*b>c*d){printf("%d",a*b);} else{printf("%d",c*d);} return 0;}

In the Attacking war game Amit and Arun will have a battle using their monsters.The health and strength of Amit's monster are A and B, respectively, and those of Arun's monster are C and D, respectively.The two monsters will take turns attacking, in the order Amit's, Arun's, Amit's, Arun's, ... Here, an attack decreases the opponent's health by the value equal to the attacker's strength. The monsters keep attacking until the health of one monster becomes 0 or below.

 #include <stdio.h> int main() {int a,b,c,d; scanf("%d %d %d %d",&a,&b,&c,&d); if(a-d>=c-b) printf("Yes"); else printf("No");                return 0; }

Three brothers want to take a photo with family members. The photographer is capturing the photo from a long distance. Some of the family members are standing behind that brothers and those people are not visible to the photographer. So the photographer gets confused with the heights of three brothers. To get clarity, he asked, "who is the tallest person among those three brothers? But no one responded clearly. Can you help the photographer in finding the tallest among the three brothers?

 #include <stdio.h> int main() {   int bro1,bro2,bro3,tallest;     scanf("%d %d %d",&bro1,&bro2,&bro3);     if(bro1>bro2&&bro1>bro3)   {  tallest=bro1; printf("%d",tallest);}     else if (bro2>bro3)   {  tallest=bro2; printf("%d",tallest);}     else   {   printf("%d",bro3);} return 0; }