Posts

Showing posts with the label c programming

Akash the die heart fan of AR Rahman went to the live concert happened in Bangalore with his family members.The event management firm responsible for the event arranged the seats for the audience in descending order of maximum number of tickets booked for single family.

 #include <stdio.h> int main() {int nooffamilymembers; scanf("%d",&nooffamilymembers); int r=nooffamilymembers; for(int i=1;i<=nooffamilymembers;i++){     for(int j=1;j<=r;j++){         printf("%d ",r);     }r--;     printf("\n");} return 0; }

Advika is trying to solve the puzzle problem during Mathematics class hour. she has a graph paper with G X N rows and columns, and the puzzle question is, an NCC training base in each cell for a total of G X N bases. He wants to drop food items to every point based on strategic points on the graph paper, marking each drop point with a red dot. If a base contains at least one food package inside or on top of its border fence, then it's considered to be supplied. For example: if Advika has four bases in a 2x2 grid. If he drops a single food package where the walls of all four bases intersect, then those four cells can access the food package.

 #include<stdio.h> int req,x,y; int NccCells(int x,int y) {req=((x+1)/2)*((y+1)/2);     return req;} int main() {    scanf("%d%d",&x,&y);     printf("%d",NccCells(x,y)); return 0;}

There are N students standing in a row and numbered 1 through N from left to right. You are given a string S with length N, where for each valid i, the i-th character of S is 'g' if the i-th student is a girl or 'b' if this student is a boy. Students standing next to each other in the row are friends.

 #include<stdio.h> #include<string.h> int main() {     char students[100001];     int t,j,count=0,length;     scanf("%d",&t);     while(t--){     count=0;     scanf("%s",students);     length=strlen(students);         for(j=0;j<length;j++){             if((students[j]=='g'&&students[j+1]=='b')||(students[j]=='b'&&students[j+1]=='g')){             count++;             j++;}             else             continue;}     printf("%d\n",count);}     return 0; }

Lokesh have been given a String S consisting of uppercase and lowercase English alphabets. Lokesh need to change the case of each alphabet in this String. That is, all the uppercase letters should be converted to lowercase and all the lowercase letters should be converted to uppercase.

#include <stdio.h> #include<string.h> int main() {char ch[100]; int length,i;  scanf("%s",ch); length=strlen(ch); for(i=0;i<length;i++) {   if(ch[i]>=65&&ch[i]<=90)   ch[i]=ch[i]+32;   else if(ch[i]>=97)   ch[i]=ch[i]-32; } printf("%s",ch);                return 0; } 

Laaslya is planning to go to the cinema theater to spend her weekend vacation. Her friends Tina, Caleb, and Jocelyn all knew about Laasya's plan. They say we are coming too, but she thinks to ignore them because only Laasya has enough money to pay for the cinema ticket.The puzzle is Tower of Hanoi is a mathematical puzzle where we have three rods and n disks. The objective of the puzzle is to move the entire stack to another rod. the number of the disk will be given as input obeying the following simple rules:1) Only one disk can be moved at a time.2) Each move consists of taking the upper disk from one of the stacks and placing it on top of another stack i.e. a disk can only be moved if it is the uppermost disk on a stack.3) No disk may be placed on top of a smaller disk.

 #include <stdio.h> void tHanoi(int n,char from_rod,char to_rod,char aux_rod)  {     if(n==1){         printf("\nMove disk 1 from rod %c to rod %c",from_rod,to_rod);         return; }     tHanoi(n-1,from_rod,aux_rod,to_rod);     printf("\nMove disk %d from rod %c to rod %c",n,from_rod,to_rod);     tHanoi(n-1,aux_rod,to_rod,from_rod); } int main() {     int num;   scanf("%d",&num);     tHanoi(num,'A','C','B');  return 0;       }

Laaysa with his friends going to the theatre for a movie. The seating arrangement is triangular in size. Theatre staffs insisted the audience to sit in odd row if the seat number is odd and in even row if the seat number is even.But the instruction is very confusing for Laaysa and his friends.So help them with the seating layout so that they can sit in correct seats.

 #include<stdio.h> int main() {int t,i,j,c; scanf("%d",&t); for(i=1;i<=t;i++){     if(i%2==0)     c=2;     else     c=1;     for(j=1;j<=i;j++){         printf("%d ",c);         c+=2;     }printf("\n"); }              return 0;}

Lokesh usually likes to play cricket, but now, he is bored of playing it too much, so he is trying new games with strings. Lokesh's friend Tina gave him binary strings S and R, each with length N, and told him to make them identical. However, unlike Tina, Lokesh does not have any superpower and Tina lets Lokesh perform only operations of one type: choose any pair of integers (i,j) such that 1≤i,j≤N and swap the i-th and j-th character of S.

#include <stdio.h> int main() {     char s[100],r[100];     int t,i,N;     scanf("%d",&t);     while(t--)     {         int count1=0,count2=0;         scanf("%d",&N);         scanf("%s%s",s,r);         for(i=0;i<N;i++)         {             if(s[i]=='1') count1++;             if(r[i]=='1') count2++;         }         if(count1==count2)         printf("YES\n");         else         printf("NO\n");     }     return 0; } 

Nathan wants to implement wildcard pattern matching supporting only the wildcard '?'. The wildcard character '?' can be substituted by any single lower case English letter for matching. He has two strings X and Y of equal length, made up of lower case letters and the character '?'. He wants to know whether the strings X and Y can be matched or not.

#include <stdio.h> #include<string.h> #include<ctype.h> int main()   {int MAX=10;  char a[MAX],b[MAX];  int t;  scanf("%d",&t);  while(t--){  scanf("%s",a);  scanf("%s",b);  int i,  n=strlen(b),no=0;  for(i=0;i<n;i++)  {if(isalpha(a[i])&&isalpha(b[i])&&a[i]!=b[i])  no++;}  if(no>0)  printf("No\n");  else printf("Yes\n"); } return 0; } 

Afghanistan has surrounded by attackers. A truck enters the city. The driver claims the load is food and medicine from Pakistanis. Yasir is one of the soldier in Afghanistan. He doubts about the truck, maybe it's from the siege. He knows that a tag is valid if the sum of every two consecutive digits of it is even and its letter is not a vowel. If the tag is invalid then Yasir need to arrest the driver of the truck with invalid tab. If it is valid the truck is allowed inside the country.Can you help yasir in determine if he need to arrest or allow the truck?

 #include <stdio.h> int main() {int n=0,c=0; char tag[9]; scanf("%s",tag); while(n<8){     if(tag[n+1]=='-')     n+=2;     else if((tag[n]+tag[n+1])%2==0)     c++;     n++;} if(c>=4)printf("Allowed"); else printf("Arrest"); return 0; }

Ambikapathy wants to decorate his girlfriend Amaravathi's house with a series of lights. The number of lights is M. Initially, all the lights are switched off. Ambikapathy finds that there are K numbers of buttons, each of them is connected to a set of lights. Ambikapathy can press any of these buttons. When the button is pressed, it turns on all the lights it’s connected to. Can Ambikapathy accomplish his task to switch on all the lights? If Ambikapathy presses the button such that some lights connected to it are already turned on, they do not change their state, i.e. remain turned on. Help him in his task to impress his valentine.

 #include <stdio.h> int main() {  int  k,m,count=0; scanf("%d %d",&k,&m); while(k--) {  int lights[m];  int i; for(i=0;i<m;i++) { scanf("%d",&lights[i]); } for(i=0;i<m;i++){ if(lights[i]<=m); else{ count+=1; } } } if(count==0){ printf("YES"); } else{ printf("NO"); } return 0; }

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; }

Selvan was playing with the a object of random size for stress relief. Selvan knows that the Length, Width, and Height of the object. But he would like to know the surface area of the object he is playing with. Can you help him in finding it?

 #include <stdio.h> int main() {     int length,width,height,surfacearea;     scanf("%d%d%d",&length,&width,&height);     surfacearea=2*((width*length)+(length*height)+(height*width));     printf("%d",surfacearea); return 0; }