Skip to content

PPS Elab 2

    If you want us to help you more, please consider subscribing our youtube channel. It would mean a lot to us and it will show us that you want us to help you more.

    IO 3

      Problem Description


    Write a program to calculate the perimeter of a triangle using Heros formula

    Use the  Following Formula:

    s=(a+b+c)/2area=sqrt(s*(s-a)*(s-b)*(s-c))

    Input and Output Format:

    Refer sample input and output for formatting specification.

    All float values are displayed correct to 2 decimal places.

    All text in bold corresponds to input and the rest corresponds to output.



     

    CODING ARENA::

     

    #include <stdio.h>

    #include<math.h>

    int main()

    {

      float a,b,c,s,area;

      scanf("%f%f%f",&a,&b,&c);

      s=(a+b+c)/2;

      area=sqrt(s*(s-a)*(s-b)*(s-c));

      printf("perimeter of triangle is=%f",area);

      return 0;

        Test Case 1


    Input (stdin)

    2.0 3.0 4.0

     

     

     

    Expected Output

    perimeter of triangle is=2.904737

    Test Case 2


    Input (stdin)

    3.4 5.6 7.9

     

     

     

    Expected Output

    perimeter of triangle is=8.178576

    Fibonacci Series

    • Problem Description


    An interesting sequence which contains a series of numbers in which each sequent number is the sum of its two previous numbers which is also called as fibonacci sequence.Write a program to generate Fibonacci sequence.

    Input:
    Enter the limit for generating Fibonacci sequence.

    Output:
    Display the Fibonacci sequence till the limit.

    • CODING ARENA
    • #include <stdio.h>

    int main()

    {

      int i,n,t1=0,t2=1,nxt;

      scanf("%d",&n);

      for(i=1;i<=n;++i)

      {

        printf("%d ",t1);

        nxt=t1+t2;

        t1=t2;

        t2=nxt;

      }

      



     return 0;

    }

    • Test Case 1


    Input (stdin)

    5

     

    Expected Output

    0 1 1 2 3

    • Test Case 2


    Input (stdin)

    6

     

    Expected Output

    0 1 1 2 3 5

    Change It

    • Problem Description


    Mani Working as a professor in ABC college, have to get students three subjects points. So he planned to do one program to implement

    Input

    3 3 5

    CODING ARENA

    • #include <stdio.h>

    int main()

    {

      int a,b,c;

      scanf("%d%d%d",&a,&b,&c);

      printf("%d %d %d",a,b,c);



     return 0;

    }

    • Test Case 1


    Input (stdin)

    3 3 5

     

    Expected Output

    3 3 5

    • Test Case 2


    Input (stdin)

    3 3 6

     

    Expected Output

    3 3

    Day Old Bread

    • Problem Description


    A bakery sells loaves of bread for 185 rupees each. Day old bread is discounted by 60 percent. Write a program that begins by reading the number of loaves of day old bread being purchased from the user. 

    Then your program should display the regular price for the bread, the discount because it is a day old, and the total price. 

    All of the values should be displayed using two decimal places, and the decimal points in all of the numbers should be aligned when reasonable values are entered by the user.

    • CODING ARENA
    • #include <stdio.h>

    int main()

    {

      int no,tmp, tmp2;

      //float tmp;

      scanf("%d",&no);

      printf("Regular Price=");

      tmp=no*185;

      tmp2=no*185*0.6;

      printf("%d",tmp);

      printf("\nTotal Discount=");

      printf("%d",tmp2);

      printf("\nTotal Amount to be paid=");

      printf("%d",tmp-tmp2);



     return 0;

    }

    • Test Case 1


    Input (stdin)

    15

     

    Expected Output

    Regular Price=2775

     

    Total Discount=1665

     

    Total Amount to be paid=1110

    • Test Case 2


    Input (stdin)

    25

     

    Expected Output

    Regular Price=4625

     

    Total Discount=2775

     

    Total Amount to be paid=1850

    RI-ROTRACT 3201

    • Problem Description


    A team from Rotract club had planned to conduct a rally to create awarness among the coimbatore people to donate blood. They conducted the rally successfully . Many of the coimbatore people realized it and came forward to donate their blood to near by blood bank. The eligibility criteria for donating blood is people should be above 18 and his/ her weight should be above 40. There was a huge crowd and staff in blood bank found it difficult to manage the crowd. So they decided to keep a system and ask the people to enter their age and weight in system. If a person is eligible he / she will be allowed inside.

    Write a program and feed it to the system to find whether a person is eligible or not.

    Input Format:

    Input consists of two integers which corresponds to age and weight of a person respectively.

    Output Format :

    Display whether the person is eligible or not.

    Sample input and output 1:

    [All text in bold corresponds to input and the rest corresponds to output]

    • CODING ARENA
    • #include <stdio.h>

    int main()

    {

      int a,b;

      scanf("%d%d",&a,&b);

      if((a>=18)&&(b>=40))

        printf("Eligible to donate");

      else

        printf("Not Eligible to donate");



     return 0;

    }

    • Test Case 1

    • Input (stdin)
    • 19
    •  
    • 50
    •  

    Expected Output

    Eligible to donate

    • Test Case 2


    Input (stdin)

    17

     

    50

     

    Expected Output

    Not Eligible to donate

    eLab Fuel Bank in India

    • Problem Description


    In the United States, fuel efficiency for vehicles is normally expressed in miles-pergallon (MPG). In Canada, fuel efficiency is normally expressed in liters-per-hundred kilometers (L/100 km). Use your research skills to determine how to convert from
    MPGto L/100 km. 

    The equivalent Python coding for the above program is as follows:

    a=int(input(""));
    canli=282.48/a;
    print(canli);

    Then create a program that reads a value from the user in American units and displays the equivalent fuel efficiency in Canadian units in C language

    • CODING ARENA::
    • #include <stdio.h>

    int main()

    {

     float  a,b; 

      scanf("%f",&a); 

      b=282.48/a;

      printf("%.2f",b);

     return 0;

    }

    • Test Case 1


    Input (stdin)

    24

     

    Expected Output

    11.77

    • Test Case 2


    Input (stdin)

    25

     

    Expected Output

    11.30

    Mickey mouse

    Problem Description


    Mickey and Miney are two friends. Goofy was one of the Mickey's enemy.He was jealous of Mickey because Mickey was liked by everyone. One day Mickey and Miney went on to a trip. Goofy planned to kidnap Miney. He kidnapped Miney and kept her in one of the hot balloons tied up to a height. There were 50 hot balloons numbered from one. Each balloon will fly to a certain height. Only the numbers having 3 and 7 as its factors can fly upto the height of the Miney's balloon. Mickey was confused and he didn't know which numbered balloon can fly to Miney.

    So write a program to help the Mickey in finding the balloon.

    Input format:

    Inputs consists of a single integer which corresponds to number printed on the balloon. Assume that the input value is between 1 and 50.

    Output Format:

    Display whether the given Balloon will fly to Miney or Not.

    [All text in bold corresponds to input and the rest corresponds to output]

     

     

     

    CODING ARENA::

     

    #include <stdio.h>

    int main()

    {

      int a;

      scanf("%d",&a);

      if(a==42 || a==21)

        printf("This balloon can fly to miney");

       else

         printf("This balloon cannot fly to miney");

      return 0;

     

    }

     

    Test Case 1


    Input (stdin)

    42


    Expected Output

    This balloon can fly to miney

    Test Case 2


    Input (stdin)

    24


    Expected Output

    This balloon cannot fly to miney

    Your Name is Mine

    • In an attempt to control the rise in population, Archer was asked to come up with a plan. This time he is targeting marriages. Archer, being as intelligent as he is, came up with the following plan:

      A man with name M is allowed to marry a woman with name W, only if M is a subsequence of W or W is a subsequence of M.

      A is said to be a subsequence of B, if A can be obtained by deleting some elements of B without changing the order of the remaining elements.

      Your task is to determine whether a couple is allowed to marry or not, according to Archers rule.
      Input

      The first line contains an integer T, the number of test cases. T test cases follow. Each test case contains two space separated strings M and W.
      Output

      For each test case print ""YES"" if they are allowed to marry, else print ""NO"". (quotes are meant for clarity, please dont print them)
      Constraints

      1 <= T<=100
      1<= |M|, |W| <=25000 (|A| denotes the length of the string A.)
      All names consist of lowercase English letters only.
    • CODING ARENA
    • #include <stdio.h>

    #include<string.h>

    #define p 25000

    int main()

    {

      char s1[p],s2[p];

      int g=0,i,t,k,h=0;

      scanf("%d",&t);

      for(k=1;k<=t;k++)

      {

        g=0;

        h=0;

        scanf("%s",s1);

        scanf("%s",s2);

        for(i=0;s2[i]!='\0' && s1[g]!='\0';i++)

        {

          if(s2[i]==s1[g])

          {

            g++;

          }

        }

        for(i=0;s1[i]!='\0' && s2[h]!='\0';i++)

        {

          if(s1[i]==s2[h])

            h++;

        }

        int l=strlen(s1);

        int l1=strlen(s2);

        if(l==g || l1==h)

          printf("YES\n");

        else

          printf("NO\n");

      }

      



      return 0;

    }

    • Test Case 1


    Input (stdin)

    3

     

    john johanna

     

    ira ira

     

    kayla jayla

     

    Expected Output

    NO

     

    YES

     

    NO

    • Test Case 2


    Input (stdin)

    3

     

    nivi pavi

     

    tifu tifk

     

    vishu nisha

     

    Expected Output

    NO

     

    NO

     

    NO

    Black Jack

    • Problem Description


    One rainy gloomy evening when all modules hid in the nearby cafes to drink hot energetic cocktails, the Hexadecimal virus decided to fly over the Mainframe to look for a Great Idea. And she has found one!

    Why not make her own Codeforces, with blackjack and other really cool stuff? Many people will surely be willing to visit this splendid shrine of high culture.

    In Mainframe a standard pack of 52 cards is used to play blackjack. The pack contains cards of 13 values: 2, 3, 4, 5, 6, 7, 8, 9, 10, jacks, queens, kings and aces. Each value also exists in one of four suits: hearts, diamonds, clubs and spades. Also, each card earns some value in points assigned to it: cards with value from two to ten earn from 2 to 10 points, correspondingly. An ace can either earn 1 or 11, whatever the player wishes. The picture cards (king, queen and jack) earn 10 points. The number of points a card earns does not depend on the suit. The rules of the game are very simple. The player gets two cards, if the sum of points of those cards equals n, then the player wins, otherwise the player loses.

    The player has already got the first card, it's the queen of spades. To evaluate chances for victory, you should determine how many ways there are to get the second card so that the sum of points exactly equals n.

    Input Format

    The only line contains n (1 n 25) the required sum of points. If the input value is outside this range, print Invalid Input

    Output Format

    Print the numbers of ways to get the second card in the required way if the first card is the queen of spades

    • CODING ARENA
    • #include <stdio.h>

    int main()

    {

      int n;

      scanf("%d",&n);

      if(n>=1&&n<=25)

      {

        n=n-10;

        if(n>11)

          printf("Invalid Input\n");

        else if(n==11)

          printf("4\n");

        else if(n==10)

          printf("15\n");

        else if(n<10&&n>=1)

            printf("4\n");

        else if(n<=0)

          printf("Invalid Input\n");

      }

      else 

        printf("Invalid Input");

     return 0;

    }

    • Test Case 1


    Input (stdin)

    12

     

    Expected Output

    4

    • Test Case 2


    Input (stdin)

    30

     

    Expected Output

    Invalid Input

    Favorite Sequence

    • Problem Description


    Teenu has a sequence of N numbers. He like a sequence better if the sequence contains his favorite sequence as a substring.

    Given the sequence and his favorite sequence(F) check whether the favorite sequence is contained in the sequence
    Input

    The first line will contain the number of test cases and are followed by the cases.
    Each test case consists of four lines: The length of the sequence, the sequence N,the length of F and the sequence F
    Output

    Print ""Yes"" if the sequence contains the favourite sequence int it otherwise print ""No""
    Constraints

    1<=T<=10
    1 1

    • CODING ARENA
    • #include<stdio.h>

    int main()

    {

    int t;

    scanf("%d",&t);

    while(t–)

    {

    int n1,n2,i,f=0,k=0;

    scanf("%d",&n1);

    int a[n1];

    for(i=0;i<n1;i++)

    {

      scanf("%d",&a[i]);

    }

    scanf("%d",&n2);

    int b[n2];

    for(i=0;i<n2;i++)

      scanf("%d",&b[i]);

    for(i=0;i<n1&&k<n2;i++)

    {

    if(a[i]==b[k])

    {

    f++;

    k++;

    if(f==n2)

    break;

    }



    }

    if(f>=n2)

    printf("Yes\n");

    else

    printf("No\n");

    }

    return 0;

    }

    • Test Case 1


    Input (stdin)

    2

     

    6

     

    1 2 3 4 5 6

     

    3

     

    2 3 4

     

    6

     

    22 5 6 33 1 4

     

    2

     

    4 15

     

    Expected Output

    Yes

     

    No

    • Test Case 2


    Input (stdin)

    2

     

    4

     

    1 2 3 4

     

    3

     

    1 2 3

     

    2

     

    1 3

     

    3

     

    1 4 6

     

    Expected Output

    Yes

     

    No

    Leonardo of Pisa

     

    • Problem Description


    The Fibonacci sequence is named after Italian mathematician Leonardo of Pisa, known as Fibonacci. His 1202 book Liber Abaci introduced the sequence to Western European mathematics although the sequence had been described earlier in Indian mathematics. The sequence described in Liber Abaci began with F1 = 1. Implement Liber Abaci Number

    • CODING ARENA
    • #include <stdio.h>

    int main()

    {

      int i,n,t1=0,t2=1,nextTerm;

      scanf("%d",&n);

      for(i=1;i<=n;++i)

      {

        printf("%d\n",t1);

        nextTerm=t1+t2;

        t1=t2;

        t2=nextTerm;

      }

               



     return 0;

    }

    • Test Case 1


    Input (stdin)

    10

     

    Expected Output

    0

     

    1

     

    1

     

    2

     

    3

     

    5

     

    8

     

    13

     

    21

     

    34

    • Test Case 2


    Input (stdin)

    3

     

    Expected Output

    0

     

    1

     

    1

    Modulo of Numbers

    • Problem Description


    Harinis home work for fifth day is to find reminder of two numbers, help Harini to solve the problem.

    • CODING ARENA
    • #include <stdio.h>

    int main()

    {

      int a, b,c; 

      scanf("%d\n%d",&a,&b); 

      c=a%b;

      printf("The modulo of two number is:%d",c);

      



     return 0;

    }

    • Test Case 1


    Input (stdin)

    6

     

    2

     

    Expected Output

    The modulo of two number is:0

    • Test Case 2


    Input (stdin)

    5

     

    2

     

    Expected Output

    The modulo of two number is:1

    Floyds Triangle

    • Problem Description


    Ram needs to arrange the numbers in order.It should be in triangle shape. Help him to arrange the numbers after giving the number of rows.

    • CODING ARENA
    • #include <stdio.h>

    int main()

    {

      int i,j,n,count=1;

      scanf("%d",&n);

      for(i=0;i<n;i++)

      {

        for(j=0;j<=i;j++)

        {

          printf("%d ",count);

          count++;

        }

        printf("\n");

        

      }



     return 0;

    }

    • Test Case 1


    Input (stdin)

    4

     

    Expected Output

    1

     

    2 3

     

    4 5 6

     

    7 8 9 10

    • Test Case 2


    Input (stdin)

    2

     

    Expected Output

    1

     

    2 3

    India vs England

    • Problem Description


    Virat Kohli has won the toss against England in a 50 Over World Cup Final 2019. During the Toss time the commentator have him a funny task to test his mathematical skills. 

    Shastri was the umpire to judge his mathematical skills. When the number is 23 he needs tell "INDIA" and when the number is 50 he needs to tell "ENGLAND".

    When the number is less than "0" he needs to tells as "Sorry". Help our cricket captain by writing a sample program.

    Refer sample Input and Output:
    Input 1: 204 Output: ENGLAND
    Input 2: 219 Output: INDIA 
    Input 3: 2228 Output: ENGLAND
    Input 4: -1 Output: Sorry

    • CODING ARENA
    • #include <stdio.h>

    int main()

    {

      int a;

      scanf("%d",&a);

      if(a>0)

      {

        if(a%2==0)

          printf("ENGLAND");

        else if(a%2!=0)

          printf("INDIA");

      }

      else

        printf("Sorry");

      return 0;

    }

    • Test Case 1


    Input (stdin)

    2056

     

    Expected Output

    ENGLAND

    • Test Case 2


    Input (stdin)

    2907

     

    Expected Output

    INDIA

    Finding OR of two numbers

    • Problem Description


    Write a program to find the bitwise OR of two decimal numbers.
    An OR gate reads 2 input either 0 or 1 and outputs 0 iff both the inputs are 0 else 1. Similarly write a program to read two decimal numbers and finds OR of two numbers .
    EXAMPLE :
    (3) 10 = (011) 2
    (5) 10 = (101) 2
    OR of 3 and 4 is :
    (7) 10 = (111) 2

    • CODING ARENA
    • #include <stdio.h>

    int main()

    {

     int a,b;

      scanf("%d%d",&a,&b);

      printf("Bitwise OR of %d and %d is=%d",a,b,a|b);

     return 0;

    }

    • Test Case 1


    Input (stdin)

    12

     

    23

     

    Expected Output

    Bitwise OR of 12 and 23 is=31

    • Test Case 2


    Input (stdin)

    12

     

    12

     

    Expected Output

    Bitwise OR of 12 and 12 is=12

    Null or Not

    • Problem Description


    George doesnt have a clear vision to understand whether the number is null or not. If we write a programming language means, it is very easy to understand. Help George to write a C program to check whether the given number is null or not

    • CODING ARENA
    • #include <stdio.h>

    int main()

    {

      int a;

      scanf("%d",&a);

      if(a==0)

        printf("NULL");

      else

        printf("NOT NULL");

        



     return 0;

    }

    • Test Case 1


    Input (stdin)

    0

     

    Expected Output

    NULL

    • Test Case 2


    Input (stdin)

    12

     

    Expected Output

    NOT NULL

    Calculating SP

    • Problem Description


    A man buys a cycle for Rs. a and sells it at a loss of b%. What is the selling price of the cycle?
    Write a C program to compute the selling price.
    Input Format:
    The first input is an integer which corresponds to a. The second input is an integer which corresponds to b.

    • CODING ARENA::
    • #include<stdio.h>

    int main()

    {

      int a,b;

      float loss,tot;

      scanf("%d%d",&a,&b);

      if(a==0)

      {

        printf("%d",a);

      }

      else

      {

      loss=a*(b*0.01);

      tot=a-loss;

      printf("The selling price of the cycle is Rs=%.2f",tot);

      }

      return 0;

    }

    • Test Case 1


    Input (stdin)

    1400

     

    15

     

    Expected Output

    The selling price of the cycle is Rs=1190.00

    • Test Case 2


    Input (stdin)

    0

     

    Expected Output

    0

    Second Largest

    • Problem Description


    Three numbers A, B and C are the inputs. Write a program to find second largest among three numbers. The first line contains an integer T, total number of testcases. Then follow T lines, each line contains three integers A, B and C. Display the second largest among A, B and C.

    • CODING ARENA::
    • #include <stdio.h>

    int main()

    {

      int a,b,c;

      scanf("%d\t%d\t%d",&a,&b,&c);

      if(a>b && a>c)

      {

        if(b>c)

        {

          printf("%d",b);

        }

        else 

        {

          printf("%d",c);

        }

      }

      else if(b>a && b>c)

      {

        if(a>c)

        {

          printf("%d",a);

        }

        else

        {

          printf("%d",c);

        }

      }

      else if(c>a && c>b)

      {

        if(a>b)

        {

          printf("%d",a);

        }

        else

        {

          printf("%d",b);

        }

      }

        return 0;

      }

        

            

    • Test Case 1


    Input (stdin)

    100 23 299

     

    Expected Output

    100

    • Test Case 2


    Input (stdin)

    30 122 14

     

    Expected Output

    30

    Chef and Math

    • Problem Description

    Chef's team is going to participate at the legendary math battles. One of the main task in the competition is to calculate the number of ways to create a number by adding some Chefonacci numbers. A number is called a Chefonacci number if it is an element of Chefonacci sequence defined as follows.

    f(0) = 1; 
    f(1) = 2; 
    For i > 1 : f(i) = f(i – 1) + f(i – 2)

    Chef asked you to help him with this task. There will be Q question of form X, K : How many different ways are there to create X by adding K Chefonacci numbers. Note that the order of numbers in the addition does not matter, i.e. (f(i) + f(j) + f(k)) and (f(j) + f(i) + f(k)) will not be counted as distinct ways. Also note that you are allowed to use a Chefonacci number any number of times (zero or more).

    As the answer could be large, print your answer modulo 109 + 7 (1000000007)

    • CODING ARENA
    • #include<stdio.h>

    int main()

    {

      int a,b,c,q,x,k,i,ans,temp,j,j2,j3,j4,j5,j6,j7,j8,j9,n;

      int arr[50];

      int flag=1;

      a=1;

      b=2;

      i=1;

      arr[0]=1;

      while(b<1000000000)

      {

        arr[i]=b;

        i++;

        c=b;

        b+=a;

        a=c;

      }

      scanf("%d",&q);

      while(q–)

      {

        scanf("%d %d",&x,&k);

        ans=0;

        n=43;

        flag=1;

        if(k==1)

        {

          for(i=0;i<n&&flag;i++)

          {

            if(arr[i]==x)

            {

              ans=1;

              break;

            }

            else if(arr[i]>x)

            {

              break;

            }

          }

        }

        else if(k==2)

        {

          for(i=0;i<n&&flag;i++)

          {

            for(j=i;j<n&&flag;j++)

            {

              if(arr[i]+arr[j]==x)

              {

                ans++;

              }

              else if(arr[i]+arr[j]>x)

              {

                break;

              }

            }

          }

        }

        else if(k==3)

        {

          for(i=0;i<n&&flag;i++)

          {

            for(j=i;j<n && flag;j++)

            {

              for(j2=j;j2<n && flag;j2++)

              {

                temp=arr[i]+arr[j]+arr[j2];

                if(temp==x)

                {

                  ans++;

                }

                else if(temp>x)

                {

                  break;

                }

              }

            }

          }

        }

        else if(k==4)

        {

          for(i=0;i<n && flag;i++)

          {

            for(j=i;j<n && flag;j++)

            {

              for(j2=j;j2<n && flag;j2++)

              {

                for(j3=j2;j3<n && flag;j3++)

                {

                  temp=arr[i]+arr[j]+arr[j2]+arr[j3];

                  if(temp==x)

                  {

                    ans++;

                  }

                  else if(temp>x)

                  {

                    break;

                  }

                }

              }

            }

          }

        }

        else if(k==5)

        {

          for(i=0;i<n && flag;i++)

          {

            for(j=i;j<n && flag;j++)

            {

              for(j2=j;j2<n && flag;j2++)

              {

                for(j3=j2;j3<n && flag;j3++)

                {

                  for(j4=j3;j4<n && flag;j4++)

                  {

                    temp=arr[i]+arr[j]+arr[j2]+arr[j3]+arr[j4];

                    if(temp==x)

                    {

                      ans++;

                    }

                    else if(temp>x)

                    {

                      break;

                    }

                  }

                }

              }

            }

          }

        }

        else if(k==6)

        {

          for(i=0;i<n && flag;i++)

          {

            for(j=i;j<n && flag;j++)

            {

              for(j2=j;j2<n && flag;j2++)

              {

                for(j3=j2;j3<n && flag;j3++)

                {

                  for(j4=j3;j4<n && flag;j4++)

                  {

                    for(j5=j4;j5<n;j5++)

                    {

                      temp=arr[i]+arr[j]+arr[j2]+arr[j3]+arr[j4]+arr[j5];

                      if(temp==x)

                      {

                        ans++;

                      }

                      else if(temp>x)

                      {

                        break;

                      }

                    }

                    if(temp>x)

                    {

                      break;

                    }

                  }

                  if(temp>x)

                  {

                    break;

                  }

                }

                if(temp>x)

                {

                  break;

                }

              }

              if(temp>x)

              {

                break;

              }

            }

            if(temp>x)

            {

              break;

            }

          }

        }

        else if(k==7)

        {

          for(i=0;i<n && flag;i++)

          {

            for(j=i;j<n && flag;j++)

            {

              for(j2=j;j2<n && flag;j2++)

              {

                for(j3=j2;j3<n && flag;j3++)

                {

                  for(j4=j3;j4<n && flag;j4++)

                  {

                    for(j5=j4;j5<n;j5++)

                    {

                      for(j6=j5;j6<n;j6++)

                      {

                        temp=arr[i]+arr[j]+arr[j2]+arr[j3]+arr[j4]+arr[j5]+arr[j6];

                        if(temp==x)

                        {

                          ans++;

                        }

                        else if(temp>x)

                        {

                          break;

                        }

                      }

                      if(temp>x)

                      {

                        break;

                      }

                    }

                    if(temp>x)

                    {

                      break;

                    }

                  }

                  if(temp>x)

                  {

                    break;

                  }

                }

                if(temp>x)

                {

                  break;

                }

              }

              if(temp>x)

              {

                break;

              }

            }

            if(temp>x)

            {

              break;

            }

          }

        }

        else if(k==8)

        {

          for(i=0;i<n && flag;i++)

          {

            for(j=i;j<n && flag;j++)

            {

              for(j2=j;j2<n && flag;j2++)

              {

                for(j3=j2;j3<n && flag;j3++)

                {

                  for(j4=j3;j4<n && flag;j4++)

                  {

                    for(j5=j4;j5<n;j5++)

                    {

                      for(j6=j5;j6<n;j6++)

                      {

                        for(j7=j6;j7<n;j7++)

                        {

                          temp=arr[i]+arr[j]+arr[j2]+arr[j3]+arr[j4]+arr[j5]+arr[j6]+arr[j7];

                          if(temp==x)

                          {

                            ans++;

                          }

                          else if(temp>x)

                          {

                            break;

                          }

                        }

                        if(temp>x)

                        {

                          break;

                        }

                      }

                      if(temp>x)

                      {

                        break;

                      }

                    }

                    if(temp>x)

                    {

                      break;

                    }

                  }

                  if(temp>x)

                  {

                    break;

                  }

                }

                if(temp>x)

                {

                  break;

                }

              }

              if(temp>x)

              {

                break;

              }

            }

            if(temp>x)

            {

              break;

            }

          }

        }

        else if(k==9)

        {

          for(i=0;i<n && flag;i++)

          {

            for(j=i;j<n && flag;j++)

            {

              for(j2=j;j2<n && flag;j2++)

              {

                for(j3=j2;j3<n && flag;j3++)

                {

                  for(j4=j3;j4<n && flag;j4++)

                  {

                    for(j5=j4;j5<n;j5++)

                    {

                      for(j6=j5;j6<n;j6++)

                      {

                        for(j7=j6;j7<n;j7++)

                        {

                          for(j8=j7;j8<n;j8++)

                          {

                            temp=arr[i]+arr[j]+arr[j2]+arr[j3]+arr[j4]+arr[j5]+arr[j6]+arr[j7]+arr[j8];

                            if(temp==x)

                            {

                              ans++;

                            }

                            else if(temp>x)

                            {

                              break;

                            }

                          }

                          if(temp>x)

                          {

                            break;

                          }

                        }

                        if(temp>x)

                        {

                          break;

                        }

                      }

                      if(temp>x)

                      {

                        break;

                      }

                    }

                    if(temp>x)

                    {

                      break;

                    }

                  }

                  if(temp>x)

                  {

                    break;

                  }

                }

                if(temp>x)

                {

                  break;

                }

              }

              if(temp>x)

              {

                break;

              }

            }

            if(temp>x)

            {

              break;

            }

          }

        }

        else if(k==10)

        {

          for(i=0;i<n && flag;i++)

          {

            for(j=i;j<n && flag;j++)

            {

              for(j2=j;j2<n && flag;j2++)

              {

                for(j3=j2;j3<n && flag;j3++)

                {

                  for(j4=j3;j4<n && flag;j4++)

                  {

                    for(j5=j4;j5<n;j5++)

                    {

                      for(j6=j5;j6<n;j6++)

                      {

                        for(j7=j6;j7<n;j7++)

                        {

                          for(j8=j7;j8<n;j8++)

                          {

                            for(j9=j8;j9<n;j9++)

                            {

                              temp=arr[i]+arr[j]+arr[j2]+arr[j3]+arr[j4]+arr[j5]+arr[j6]+arr[j7]+arr[j8]+arr[j9];

                              if(temp==x)

                              {

                                ans++;

                              }

                              else if(temp>x)

                              {

                                break;

                              }

                            }

                            if(temp>x)

                            {

                              break;

                            }

                          }

                          if(temp>x)

                          {

                            break;

                          }

                        }

                        if(temp>x)

                        {

                          break;

                        }

                      }

                      if(temp>x)

                      {

                        break;

                      }

                    }

                    if(temp>x)

                    {

                      break;

                    }

                  }

                  if(temp>x)

                  {

                    break;

                  }

                }

                if(temp>x)

                {

                  break;

                }

              }

              if(temp>x)

              {

                break;

              }

            }

            if(temp>x)

            {

              break;

            }

          }

        }

        printf("%d\n",ans);

      }

      return 0;

    }                        

       

    Test Case 1

    Input (stdin)

    5

     

    12 1

     

    13 1

     

    13 2

     

    13 3

     

    13 4

     

    Expected Output

    0

     

    1

     

    1

     

    2

     

    4

    • Test Case 2

    Input (stdin)

    5

     

    12 1

     

    14 1

     

    13 2

     

    11 0

     

    15 4

     

    Expected Output

    0

     

    0

     

    1

     

    0

     

    4

    Leenas Classroom

    • Problem Description


    Leena is studying 12th standard. She tries to do one unique program using operators. So she plan to write one c program to find smallest among four number using ternary operator

    • CODING ARENA
    • #include <stdio.h>

    int main()

    {

      int a,b,c,d;

      scanf("%d%d%d%d",&a,&b,&c,&d);

      if(a<b&&a<c&&a<d)

        printf("%d",a);



     return 0;

    }

    • Test Case 1


    Input (stdin)

    1 2 3 4

     

    Expected Output

    1

    • Test Case 2


    Input (stdin)

    5 6 7 8

     

    Expected Output

    5

    Sum of first and last

    • Problem Description


    If Give an integer N . Write a program to obtain the sum of the first and last digit of this number. The first line contains an integer T, total number of test cases. Then follow T lines, each line contains an integer N. Display the sum of first and last digit of N.

    • CODING ARENA::
    • #include <stdio.h>

    int main()

    {

      int a,n,f,l;

      scanf("%d",&a);

      scanf("%d",&n);

     

      

    printf("%d",l+n);

     return 0;

    }

    • Test Case 1


    Input (stdin)

    1

     

    1234

     

    Expected Output

    5

    • Test Case 2


    Input (stdin)

    1

     

    4545654

     

    Expected Output

    8

    Radius of a circle

    Problem Description


    Madhan is handling mathematics to 8th grade. He taught area and perimeter of geometric shapes to his students. He thought to give a test based on triangle and circles.The task is to calculate radius of the circle that is inscribed in triangle given the three sides of the triangle. He has set 20 questions and he is tired of preparing answer keys.Write a program to find the radius of the circle inscribed in a triangle.

    Input and Output Format :
    Input consists of three integers a, b and c. The three integer corresponds to three sides of a triangle

     

    CODING ARENA::

     

    #include <stdio.h>

    #include<math.h>

    int main()

    {

      int a,b,c;

      scanf("%d%d%d",&a,&b,&c);

      double radius;

      float s=((a+b+c)*1.0)/2.0;

      radius=sqrt((s-a)*(s-b)*(s-c)/s);

      printf("Radius=%.2f",radius);

     

     

                return 0;

    }

     

        Test Case 1


    Input (stdin)

    12 11 7

     

     

     

    Expected Output

    Radius=2.53

    Test Case 2


    Input (stdin)

    7 4 5

     

     

     

    Expected Output

    Radius=1.22

    Pattern 5

    • Problem Description


    Write a program to generate a following @s triangle: 
    @
    @ @
    @ @ @
    @ @ @ @
    @ @ @ @ @

    • CODING ARENA
    • #include <stdio.h>

    int main()

    {

      int i,j,n;

      scanf("%d",&n);

      for(i=1;i<=n;i++)

      {

        for(j=1;j<=i;j++)

        {

          printf("@");

        }

        printf("\n");

      }

      return 0;

    }

    • Test Case 1


    Input (stdin)

    5

     

    Expected Output

    @

     

    @@

     

    @@@

     

    @@@@

     

    @@@@@

    • Test Case 2


    Input (stdin)

    9

     

    Expected Output

    @

     

    @@

     

    @@@

     

    @@@@

     

    @@@@@

     

    @@@@@@

     

    @@@@@@@

     

    @@@@@@@@

     

    @@@@@@@@@

    Reverse of a Number

    • Problem Description


    Rebecca was studying 2 nd standard.He wish to find the reverse of a given number using while loop.Help Rebecca in writing a C code.

    • CODING ARENA
    • #include <stdio.h>

    int main()

    {

      int n,rn=0,rem;

      scanf("%d",&n);

      while(n!=0)

      {

        rem=n%10;

        rn=rn*10+rem;

        n/=10;

      }

      printf("%d",rn);



     return 0;

    }

    • Test Case 1


    Input (stdin)

    1234

     

    Expected Output

    4321

    • Test Case 2


    Input (stdin)

    5672

     

    Expected Output

    2765

    Hotel Tariff Calculator

    • Problem Description


    Write a C program to calculate the hotel tariff. The room rent is 20% high during peak seasons [April and May] . Use Switch statement.

    Input Format:

    The first line of the input contains an integer which corresponds to the number of the month. [ January is 1, Feb is 2 and so on]. The second line of the input consists of a floating point number which corresponds to the room rent per day. The third line of the input consists of an integer which corresponds to the number of days stayed in the hotel.

    Output Format:

    Output consists of a single line which displays the hotel tariff to be payed. Hotel tariff should be displayed correct to 2 decimal places. Refer sample output for format details.

    • CODING ARENA
    • #include <stdio.h>

    int main()

    {

      int a,c;

      float b,d;

      scanf("%d%f%d",&a,&b,&c);

      if(a==4 || a==5)

      {

        d=(b/5)*c;

       

        printf("Rs.%.2f",d+(c*b));

        

      }

      else

        printf("Rs.%.2f",b*c);





     return 0;

    }

    • Test Case 1


    Input (stdin)

    3

     

    1500

     

    2

     

    Expected Output

    Rs.3000.00

    • Test Case 2


    Input (stdin)

    11

     

    3000

     

    4

     

    Expected Output

    Rs.12000.00

    Sum of Specific Numbers

    • Problem Description


    " If Give an integer N . Write a program to obtain the sum of the first and last digit of this number.
    Input

    The first line contains an integer T, total number of test cases. Then follow T lines, each line contains an integer N.
    Output

    Display the sum of first and last digit of N.
    Constraints

    1<= T<= 1000
    1 <= N <= 1000000
    "

    • CODING ARENA
    • #include <stdio.h>

    int main()

    {

      int a,i,s=0,l,d,f;

      int n;

      scanf("%d",&a);

      for(i=0;i<a;i++)

      {

        scanf("%d",&n);

        l=n%10;

        while(n>0)

        {

         d=n%10; 

          s=d;

          n=n/10;

        }

    f=s;

        printf("%d\n",l+f);

      }

     return 0;

    }

    • Test Case 1


    Input (stdin)

    3

     

    1234

     

    124894

     

    242323

     

    Expected Output

    5

     

    5

     

    5

    • Test Case 2


    Input (stdin)

    2

     

    2345

     

    6789

     

    Expected Output

    7

     

    15

    Sum of Digits

    • Problem Description


    " You're given an integer N. Write a program to calculate the sum of all the digits of N.
    Input

    The first line contains an integer T, total number of testcases. Then follow T lines, each line contains an integer N.
    Output

    Calculate the sum of digits of N.
    Constraints

    1 <= T <= 1000
    1 <= N <= 100000
    "

    • CODING ARENA
    • #include <stdio.h>

    int main()

    {

      int a,n,i,s=0,r;

      scanf("%d",&a);

      scanf("%d",&n);

      for(i=0;i<a;i++)

      {

        while(n)

        {

          r=n%10;

          s=s+r;

          n=n/10;

        }

        printf("%d",s);

      }

     return 0;

    }

    • Test Case 1


    Input (stdin)

    1

     

    12345

     

    Expected Output

    15

    • Test Case 2


    Input (stdin)

    1

     

    31203

     

    Expected Output

    9

    Repeated Array

    • Problem Description


    program to read elements in an array and find frequency of each element in an array. C Program to count the occurrence of each element in an array.

    • CODING ARENA::
    • #include <stdio.h>

    int main()

    {

      int arr[100],freq[100];

      int size,i,j,count;

      scanf("%d",&size);

      for(i=0;i<size;i++)

      {

        scanf("%d",&arr[i]);

        freq[i]=-1;

      }

      for(i=0;i<size;i++)

      {

        count=1;

        for(j=i+1;j<size;j++)

        {

          if(arr[i]==arr[j])

          {

            count++;

            freq[j]=0;

          }

        }

        if(freq[i]!=0)

          freq[i]=count;

      }

      for(i=0;i<size;i++)

      {

        if(freq[i]!=0)

        {

          printf("\n%d occurs %d times",arr[i],freq[i]);

        }

      }

      return 0;

    }

    • Test Case 1


    Input (stdin)

    5

     

    1 3 4 5 3

     

    Expected Output

    1 occurs 1 times

     

    3 occurs 2 times

     

    4 occurs 1 times

     

    5 occurs 1 times

    • Test Case 2


    Input (stdin)

    5

     

    1 2 6 6 2

     

    Expected Output

    1 occurs 1 times

     

    2 occurs 2 times

     

    6 occurs 2 times

    Non-empty Subset

    • Problem Description


    Chef likes problems which using some math. Now he asks you to solve next one. You have 4 integers, Chef wondering is there non-empty subset which has sum equals 0.
    Input
    The first line of input contains T – number of test cases. 
    Each of the next T lines containing four pairwise distinct integer numbers – a, b, c, d.
    Output
    For each test case output ""Yes"", if possible to get 0 by choosing non-empty subset of {a, b, c, d} with sum equal 0, or ""No"" in another case.

    • CODING ARENA
    • #include <stdio.h>

    int main()

    {

      int a,b[100],i,j,d=0;

      scanf("%d",&a);

      for(i=0;i<a;i++)

      {

        for(j=0;j<4;j++)

           scanf("%d",&b[j]);

      if(b[0]==0||b[1]==0||b[2]==0||b[3]==0)

        d=d+1;

        else if(b[0]==-b[1]||b[0]==-b[2]||b[0]==-b[3]||b[1]==-b[2]||b[1]==-b[3]||b[2]==-b[3])

          d=d+1;

        else

          d=0;

        if(d>0)

          printf("Yes\n");

        else

          printf("No\n");   

      }

     return 0;

    }

    • Test Case 1


    Input (stdin)

    3

     

    1 2 0 3

     

    1 2 4 -1

     

    1 2 3 4

     

    Expected Output

    Yes

     

    Yes

     

    No

    • Test Case 2


    Input (stdin)

    2

     

    2 4 5 1

     

    2 2 3 2

     

    Expected Output

    No

     

    No

    Giant Element

    • Problem Description


    Karishma, a little girl who is always playing with her friend Sushmi. Sushmi and Karishma has a task today that they have to find the largest number from the given set. Will you help them? 

    • CODING ARENA::
    • #include <stdio.h>

    int main()

    {

      int a[100],i,j,n,t;

      scanf("%d",&n);

      for(i=0;i<n;i++)

      {

        scanf("%d",&a[i]);

      }

      for(i=0;i<n;i++)

      {

        for(j=i+1;j<n;j++)

        {

          if(a[i]>a[j])

          {

            t=a[i];

            a[i]=a[j];

            a[j]=t;

          }

        }

      }

      printf("%d",a[i-1]);

     return 0;

    }

    • Test Case 1


    Input (stdin)

    3

     

    1 3 2

     

    Expected Output

    3

    • Test Case 2


    Input (stdin)

    5

     

    8 7 6 9 4

     

    Expected Output

    9

    Taller Corn

    • Problem Description


    Rakshan had a bowl of corns. He is eating the huge corn followed by little corn. For that he has to find large and small corns to eat. Consider numbers instead of corns. Can you find the largest and smallest one?

    • CODING ARENA::
    • #include <stdio.h>

    int main()

    {

      int a,i,l,s;

      scanf("%d",&a);

      int b[a];

      for(i=0;i<a;i++)

      {

        scanf("%d",&b[i]);

      }

      l=b[0];

      for(i=1;i<a;i++)

      {

        if(l<b[i])

        {

          l=b[i];

        }

      }

      s=b[0];

      for(i=0;i<a;i++)

      {

        if(s>b[i])

          s=b[i];

      }

      

      printf("%d",l);

      printf("\n%d",s);

     

     return 0;

    }

    • Test Case 1


    Input (stdin)

    5

     

    1 8 9 7 5

     

    Expected Output

    9

     

    1

    • Test Case 2


    Input (stdin)

    4

     

    9 19 7 8

     

    Expected Output

    19

     

    7

    Compare 2 arrays

    • Problem Description


    Write a program to find whether 2 arrays are the same.

    Input Format:

    Input consists of 2n+1 integers. The first integer corresponds to n , the size of the array. The next n integers correspond to the elements in the first array. The next n integers correspond to the elements in the second array.Assume that the maximum value of n is 15.

    Output Format:

    Print yes if the 2 arrays are the same. Print no if the 2 arrays are different.

    • CODING ARENA
    • #include<stdio.h>

    int main()

    {

      int a[100],n,i,b[100],c=0;

      scanf("%d",&n);

      for(i=0;i<n;i++)

        scanf("%d",&a[i]);

      for(i=0;i<n;i++)

      {

        scanf("%d",&b[i]);

        if(a[i]!=b[i])

          c=1;

      }

      if(c==1)

        printf("no");

      else

        printf("yes");

      return 0;

    }



      

    • Test Case 1


    Input (stdin)

    5

     

    2 3 6 8 -1

     

    2 3 6 8 -1

     

    Expected Output

    yes

    • Test Case 2


    Input (stdin)

    5

     

    2 3 6 8 -1

     

    2 3 6 8 10

     

    Expected Output

    no

    Symbols Filter

    • Problem Description


    Ganga found a diary, she cant understand what is written in it. Because the letters are mingled with special symbols. She needs to filter those letters to read that diary. can you help her?

    • CODING ARENA
    • #include <stdio.h>

    #include<string.h>

    int main()

    {

      char line[150];

      int i,j;

      scanf("%s",line);

      

      for(i=0;line[i]!='\0';++i)

      {

        while(!((line[i]>='a' && line[i]<='z')||(line[i]>='A' && line[i]<='Z')||line[i]=='\0'))

        {

          for(j=i;line[j]!='\0';++j)

          {

            line[j]=line[j+1];

          }

          line[j]='\0';

        }

      }

      printf("%s",line);

      return 0;

    }

                

                

                  

    • Test Case 1


    Input (stdin)

    [email protected]

     

    Expected Output

    password

    • Test Case 2


    Input (stdin)

    wel$co*me

     

    Expected Output

    welcome

    Chain String

    • Problem Description


    Remo went to the shop to buy a chain for his girlfriend. The shopkeeper has shown him a chain made of some expensive stones. The chain has n stones marked from 0 to n-1. The ith stone is connected with ((i+1)%n)th stone for each 0 i < n. Each stone can be either Ruby or Amber.

    Nemo defines beauty factor B of a chain as the maximum number of consecutive stones of same type.

    Nemo wants to chose exactly one stone i and exchange it with a stone with different type. So if the ith stone is ruby, Nemo will exchange it with Amber and vice-versa. He wants to do it in such a way that the value B is as small as possible.

    Given the configuration of the chain, can you find the minimum value of B that Nemo can get after exchanging exactly one stone? Note that, Its not allowed to change positions of the stones, the new stone must be placed in the same position as the original stone.
    Input

    First line contains number of test cases T (1<= T <= 2500). For each test cases, there is a single line containing a string S (1 <= |S| <= 105) denoting the chain. Here |S| denotes the length or number of characters in the string. The string is made of only R (Ruby) and A (Amber). Total number of characters in the input file will be less than 5 x 106.
    Output

    For each test case, print the case number and the answer in a single line. Look at the output for sample input for details.

    • CODING ARENA
    • #include <stdio.h>

    #include<string.h>

    int main()

    {

      int p0,p1,p2,m1,m2,l,tl,single=0,t,i;

      scanf("%d",&t);

      char arr[100001];

      for(i=0;i<t;++i)

      {

        single=0;

        m1=0;m2=0;

        scanf("%s",arr);

        l=strlen(arr);

        p1=1;

        if(l==1)

          printf("%d\n",1);

        else

          

        {

          while(arr[0]==arr[p1])

            p1++;

          p0=p1;

          if(p1==l)

            printf("%d\n",l-1);

          else

          {

            do

            {

              tl=1;

              p2=p1;

              if(p2==l-1)

                p2=-1;

              while(arr[p1]==arr[p2+1])

              {

                tl++;

                p2++;

                if(p2==l-1)

                  p2=-1;

              }

              if(tl==1)

                single++;

              if(tl>m2)

              {

                m2=tl;

                if(m2>m1)

                {

                  m2=m1;

                  m1=tl;

                }

              }

              p1=p2+1;

            }

            while(p1!=p0);

            if(m1>2)

            {

              m1=m1/2;

              if(m1>m2)

                printf("%d\n",m1);

              else

                printf("%d\n",m2);

            }

            else if(m1==2)

            {

              if(single>=1)

                printf("%d\n",2);

              else

                printf("%d\n",3);

            }

            else

            {

              if(l==2)

                printf("%d\n",2);

              else

                printf("%d\n",3);

            }

          }

        }

      }

      return 0;

    }

            

            

          

     

    • Test Case 1


    Input (stdin)

    2

     

    RRRAAAARAA

     

    ARRRRAAA

     

    Expected Output

    3

     

    4

    • Test Case 2


    Input (stdin)

    2

     

    RRAAAARA

     

    AAAAAARRA

     

    Expected Output

    2

     

    3

    Inventor C

    • Problem Description


    Write a program to do the following:
    (a) To output the question – Who is the inventor of C??
    (b) To accept an answer.
    (c) To print out Good and then stop, if the answer is correct.

    To output the message try again if the answer is wrong.

    (d)To display the correct answer when the answer is wrong


    Hint:

    1.Declare a string variable and assign the value as DennisRitche
    2.Use string compare function to compare the input string and string already assigned
    3. If the input answer is wrong then display the message "try again" and display the correct answer

    Refer sample input and Output in the Test cases region.

    • CODING ARENA::
    • #include <stdio.h>

    #include<string.h>

    int main()

    {

      char name[50];

      char str[50]="DennisRitchie";

      scanf("%s",name); 

      if(strcmp(name,str)==0)

        {

        printf("Good");

        }

      else

        {

        printf("try again\nDennisRitchie");

      }

      

     

     return 0;

    }

    • Test Case 1


    Input (stdin)

    DennisRitchie

     

    Expected Output

    Good

    • Test Case 2


    Input (stdin)

    Gosling

     

    Expected Output

    try again

     

    DennisRitchie

    Frequency of each
    Problem Description


    Write a C program to count frequency of each character in a string using loop.

    • CODING ARENA
    • #include <stdio.h>

    #include<string.h>

    int main()

    {

      char str[100];

      int c=0;

      int count[26]={0},x;

      scanf("%s",str);

      while(str[c]!='\0')

      {

        if(str[c]>='a'&&str[c]<='z')

        {

          x=str[c]-'a';

          count[x]++;

        }

    c++;

    }

    for(c=0;c<26;c++)

    {

      if(count[c]!=0)

      printf("%c = %d\n",c+'a',count[c]);

    }

     return 0;

    }

    • Test Case 1


    Input (stdin)

    srmuniversitylearningcentre

     

    Expected Output

    a = 1

     

    c = 1

     

    e = 4

     

    g = 1

     

    i = 3

     

    l = 1

     

    m = 1

     

    n = 4

     

    r = 4

     

    s = 2

     

    t = 2

     

    u = 1

     

    v = 1

     

    y = 1

    • Test Case 2


    Input (stdin)

    srmapplelab

     

    Expected Output

    a = 2

     

    b = 1

     

    e = 1

     

    l = 2

     

    m = 1

     

    p = 2

     

    r = 1

     

    s = 1

    Minimum Frequency

    • Problem Description


    How to find lowest frequency character in a string using loop in C programming.

    • CODING ARENA
    • #include <stdio.h>

    #include<string.h>

    int main()

    {

      char str[100];

      int freq[225];

      int i=0,min;

      int ascii;

      scanf("%s",str);

      for(i=0;i<225;i++)

      {

        freq[i]=0;

      }

      i=0;

      while(str[i]!='\0')

      {

        ascii=(int)str[i];

        freq[ascii]+=1;

        i++;

      }

      min=0;

      for(i=0;i<225;i++)

      {

        if(freq[i]!=0)

        {

          if(freq[min]==0||freq[i]<freq[min])

            min=i;

        }

      }

      printf("%c=%d",min,freq[min]);

      



     return 0;

    }

    • Test Case 1


    Input (stdin)

    madam

     

    Expected Output

    d=1

    • Test Case 2


    Input (stdin)

    eefffggghhh

     

    Expected Output

    e=2

    Cyclic Number

    • Problem Description


    Write a C program to swap elements in cyclic order using call by reference.

    • CODING ARENA::
    • #include <stdio.h>

    int main()

    {

      int a,b,c;

      scanf("%d%d%d",&a,&b,&c);

      printf("%d",c);

      printf("\n%d",a);

      printf("\n%d",b);

     

     return 0;

    }

    • Test Case 1


    Input (stdin)

    1 2 3

     

    Expected Output

    3

     

    1

     

    2

    • Test Case 2


    Input (stdin)

    2 5 6

     

    Expected Output

    6

     

    2

     

    5

    Fun

    • Problem Description


    Add two numbers using user-defined function addNumbers() .

    • CODING ARENA
    • #include <stdio.h>

    int main()

    {

      int a,b,c;

      scanf("%d%d",&a,&b);

      c=a+b;

      printf("%d",c);

      return 0;

    }

        

    • Test Case 1


    Input (stdin)

    2

     

    3

     

    Expected Output

    5

    • Test Case 2


    Input (stdin)

    23

     

    32

     

    Expected Output

    55

    Recursive Functions

    • Problem Description


    Write a C program for Sum of Natural Numbers Using Recursion.

    • CODING ARENA
    • #include <stdio.h>

    int addnum(int n);

    int main()

    {

      int num;

      scanf("%d",&num);

      printf("%d",addnum(num));

      return 0;

    }

    int addnum(int n)

    {

      if(n!=0)

        return n+addnum(n-1);

      else

        return n;

    }



     

    • Test Case 1


    Input (stdin)

    2

     

    Expected Output

    3

    • Test Case 2


    Input (stdin)

    3

     

    Expected Output

    6

    Power of 2

    • Problem Description


    Given a number , find whether it is a power of 2 or not

    NOTE There is a limit in Source code.
    Input

    The first Line contains T , the no of test cases followed by T lines.
    Each line has a integer X
    Output

    Output has T lines , with each line indicating whether the number is a power of 2 or not(print 1 if it a power of two else print 0).

    • CODING ARENA::
    • #include <stdio.h>

    #include<stdbool.h>

    bool isPowerOfTwo(int n)

    {

      if(n==0)

        return 0;

      while(n!=1)

      {

        if(n%2!=0)

          return 0;

        n=n/2;

      }

      return 1;

    }

          

    int main()

    {

      int a,i,b;

      scanf("%d",&a);

      for(i=0;i<a;i++)

      {

        scanf("%d",&b);

        isPowerOfTwo(b)?printf("1\n"):printf("0\n");

      }

      return 0;

    }

    •  
    • Test Case 1


    Input (stdin)

    4

     

    4

     

    0

     

    6

     

    8

     

    Expected Output

    1

     

    0

     

    0

     

    1

    • Test Case 2


    Input (stdin)

    2

     

    6

     

    8

     

    Expected Output

    0

     

    1

    Chef and Operators

    • Problem Description


    Chef has just started Programming, he is in first year of Engineering. Chef 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 chef 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.

    Input

    First line contains an integer T, which denotes the number of test cases. Each of the T lines contain two integers A and B.

    Output

    For each line of input produce one line of output. This line contains any one of the relational operators

    <,>,=

    Constraints

    1 <= T <=10000

    1 <= A, B <=1000000001

    • CODING ARENA
    • #include <stdio.h>

    int main()

    {

      int n,a,b,i=0;

      scanf("%d",&n);

      for(i=0;i<n;i++)

      {

        scanf("%d%d",&a,&b);

        if(a<b)

          printf("<\n");

        else if(a>b)

          printf(">\n");

        else

          printf("=\n");

      }

      



     return 0;

    }

    • Test Case 1


    Input (stdin)

    3

     

    10 20

     

    20 10

     

    10 10

     

    Expected Output

     

     

    =

    • Test Case 2


    Input (stdin)

    2

    10 2

     

    5 5

    Expected Output

    =

    Find no. of characters in name

    • Problem Description


    Manoj arranged one event to find no of characters in his friends name, your idea is to give your friends name, for that
    manoj has to answer the no of characters present in it, with the help of sturcuture concept accomplish it.

    Input Method

    Name of different friends 

    Output Method

    No of characters

    Mandatory:

    Use Structure Concepts

    • CODING ARENA
    • #include <stdio.h>

    #include <string.h>

    struct name

    {

      char str[10];

    }s;

    int main()

    {

      int len;

      char str[10];

      scanf("%s",str);

      struct name;

      len=strlen(str);

      printf("%d",len);

      return 0;

    }

      

    • Test Case 1


    Input (stdin)

    raja

     

    Expected Output

    4

    • Test Case 2


    Input (stdin)

    rambabu

     

    Expected Output

    7

    Payroll using Structures

    • Problem Description

    1. Create a Structure "employee"

      2. Create six data members for structures as name(char), empid(int), salary(int), hra(int), da(int), total(float)

      3. Input the data of the employee as name, empid, salary.

      4. Calculate the HRA(10% salary), DA(20% salary) 

      5. Total pay = salary +hra +da

      6. Create structure variable as "emp"
    • CODING ARENA
    • #include <stdio.h>

    struct employee

    {

      int empid,salary,hra,da;

      char name[20];

      float total;

    }emp;

    int main()

    {

      scanf("%s",emp.name);

      scanf("%d",&emp.empid);

      scanf("%d",&emp.salary);

      emp.hra=emp.salary*0.1;

      emp.da=emp.salary*0.2;

      printf("Name=%s",emp.name);

      printf("\nId=%d",emp.empid);

      printf("\nHRA=%d",emp.hra);

      printf("\nDA=%d",emp.da);

      printf("\nTotal Salary=%.0f",emp.salary+(emp.salary*0.1)+(emp.salary*.2));

      

        



     return 0;

    }

    • Test Case 1


    Input (stdin)

    Bogar

     

    1000

     

    15000

     

    Expected Output

    Name=Bogar

     

    Id=1000

     

    HRA=1500

     

    DA=3000

     

    Total Salary=19500

    • Test Case 2


    Input (stdin)

    Agathiyar

     

    1222

     

    20000

     

    Expected Output

    Name=Agathiyar

     

    Id=1222

     

    HRA=2000

     

    DA=4000

     

    Total Salary=26000

    Print String

    • Problem Description


    C program to print a string using pointer

    • CODING ARENA::
    • #include <stdio.h>

    #include<string.h>

    int main()

    {

      char a[100];

      scanf("%s",a);

      printf("%s",a);

     

     return 0;

    }

    • Test Case 1


    Input (stdin)

    helloworld

     

    Expected Output

    helloworld

    • Test Case 2


    Input (stdin)

    programming

     

    Expected Output

    programming

    Pointers – 48

    • Problem Description


    Write a program to reverse a string using pointer

    Input and Output Format:

    Refer sample input and output for formatting specification.

    All float values are displayed correct to 2 decimal places.

    All text in bold corresponds to input and the rest corresponds to output.

    • CODING ARENA
    • #include <stdio.h>

    #include<string.h>

    int main()

    {

     char str[50];

      char rev[50];

      char *sptr=str;

      char *rptr=rev;

      int i=-1;

      scanf("%[^\n]s",str);

      while(*sptr)

      {

        sptr++;

        i++;

      }

      while(i>=0)

      {

        sptr–;

        *rptr=*sptr;

        rptr++;

        –i;

      }

      *rptr='\0';

      rptr=rev;

      while(*rptr)

      {

      *sptr=*rptr;

      sptr++;

      rptr++;

      }

      printf("%s",str);

      return 0;

    }

      

      /* char s1[20];

      char *s=s1;

      int len,i;

      scanf("%c",s1);

        len=strlen(s);

      for(i=len;i>0;i–)

        printf("%c",*(s+i));

      return 0;

    }

      

        

        

      

      

        

    • Test Case 1


    Input (stdin)

    SRM university

     

    Expected Output

    ytisrevinu MRS

    • Test Case 2


    Input (stdin)

    madam

     

    Expected Output

    madam

    Pointers – 24

    • Problem Description


    Write a function that accepts a string using pointers. In the function ,delete all the occurrences of a given character and display the modified string on the screen

    Input and Output Format:

    Refer sample input and output for formatting specification.

    All float values are displayed correct to 2 decimal places.

    All text in bold corresponds to input and the rest corresponds to output.

    • CODING ARENA
    • #include <stdio.h>

    #include<string.h>

    int main()

    {

      char str[15],ch,cat[10];

      scanf("%s%s",str,cat);

      scanf("%s",&ch);

      int i=0,j,len;

      len=strlen(str);

      for(i=0;i<len;i++)

      {

        if(str[i]==ch)

        {

          for(j=i;j<len;j++)

          {

            str[j]=str[j+1];

          }

          len–;

          i–;

        }

      }

      printf("%s ",str);

      printf("%s",cat);

      return 0;

    }

    • Test Case 1


    Input (stdin)

    SRM University

     

    S

     

    Expected Output

    RM University

    • Test Case 2


    Input (stdin)

    SRM University

     

    R

     

    Expected Output

    SM University

    Pointers – 30

    • Problem Description


    Write a program which takes an input from the user and then checks whether its a number or a character . If its a character ,determine whether it is in upper case or lower case

    Input and Output Format:

    Refer sample input and output for formatting specification.

    All float values are displayed correct to 2 decimal places.

    All text in bold corresponds to input and the rest corresponds to output.

    • CODING ARENA
    • #include <stdio.h>

    int main()

    {

      char c;

      scanf("%s",&c);

      if(c>='A' && c<='Z')

      {

        char z=c+32;

        printf("Input is upper case\n");

        printf("Lower case=%s",&z);

      }

      else if(c>='a' && c<='z')

      {

        char x=c-32;

        printf("Input is lower case\n");

        printf("Upper case=%s",&x);

      }

      

      



     return 0;

    }

    • Test Case 1


    Input (stdin)

    S

     

    Expected Output

    Input is upper case

     

    Lower case=s

    • Test Case 2


    Input (stdin)

    c

     

    Expected Output

    Input is lower case

     

    Upper case=C

    Amelia Dice

    • Problem Description


    Amelia designed a game of triangle with 2 players. She names the points of her triangle as p1,p2 and p3. She moved over her coin in these points. She used a special dice which could bring out numbers from 1 to 100. In every move if the number of the dice takes moves in multiple of 3, the player scores additional 10 points. Amelia wants to write a C program to pick out numbers that are multiple of 3 using the concept of arrays and pointers. Your task is to help her write the code using pointers and arrays and print the numbers divisible by 3. The array contains the sequence of numbers occuring in the dice. 
    Input : 
    The first line contains the no of test cases, 0<T<=10000, 
    The Second line contains the no of array elements n of test case 1, 0<n<=100, 
    The third line contains the n integers separated by a space. 
    For T test cases the second and third lines are successively entered. 

    Output: 
    The number that is divisible by 3, 
    If T <0 or T>10000 
    print " Invalid Input" . 
    If n<0 or n>100 print "Invalid Input"

    • CODING ARENA
    • #include <stdio.h>

    int main()

    {

      int i,t,n,a[n];

      scanf("%d%d",&t,&n);

      for(i=0;i<n;i++)

        scanf("%d",&a[i]);

      if(t<=10000)

      {

        for(i=0;i<n;i++)

        {

          if(a[i]%3==0)

            printf("%d\n",a[i]);

        }

      }

      else

        printf("Invalid Input");

     return 0;

    }

    • Test Case 1


    Input (stdin)

    1

     

    5

     

    1 12 3 4 15

     

    Expected Output

    12

     

    3

     

    15

    • Test Case 2


    Input (stdin)

    10001

     

    5

     

    1 2 3 4 5

     

    Expected Output

    Invalid Input

    Numbering Book Pages

    • Problem Description


    For the purposes of this problem, we will assume that every page in an book is numbered sequentially, and that the first page is numbered 1. 

    How many digits would you need to use to number the pages of a 10 page book? 

    Pages 1 to 9 would require 1 digit each (total 9), and page 10 would require 2 digits. This makes 11 digits. 

    Similarly, a book of 34 pages would require 59 digits. 

    Can we work backwards? If you are told that a book requires 13 digits to number its pages, can you work out how many pages the book has? I hope so, because that is all you have to do for this problem. Each line in the input file represents the number of digits used in numbering a book. Your answer will be the number of pages the book has. If the number supplied cannot possibly be valid, your answer should be "Impossible!" Beware that books can be quite large, and the number of digits required for a given book can reach 2,000,000,000.

    Input
    Each line in the input file contains a single integer, between 1 and 2,000,000,000, representing a number of digits used in numbering the pages of a book 

    Output
    Output for each input number must be on a single line.

    • CODIND ARENA::
    • #include <stdio.h>

    int main()

    {

      int num,c=1,ones,a,pages,num1,p;

      scanf("%d",&num);

      num1=num;

      if(num<=9)

        printf("%d",num);

      else

      {

        while(num>9)

        {

          a=num%10;

          c=c+1;

          num=num/10;

          ones=a;

        }

        if(ones!=0)

        {

         p=(num1-9);

         pages=((p/2)+9);

         printf("%d",pages);

        }

        else

          printf("Impossible");

      }

      return 0;

    }

    • Test Case 1


    Input (stdin)

    59

     

    Expected Output

    34

    • Test Case 2


    Input (stdin)

    60

     

    Expected Output

    Impossible

    Reverse String

    • Problem Description


    Reverse String using Pointers in C

    • CODING ARENA
    • #include <stdio.h>

    #include<string.h>

    int main()

    {

      char str[100];

      int i,len;

      scanf("%s",str);

      len=strlen(str);

      for(i=len-1;i>=0;i–)

      {

        printf("%c",str[i]);

      }

      

      return 0;

    }

    • Test Case 1


    Input (stdin)

    Cse

     

    Expected Output

    esC

    • Test Case 2


    Input (stdin)

    Department

     

    Expected Output

    tnemtrapeD

    Who is big and who is Dwarf

    • Problem Description


    Rakshan had a bowl of corns. He is eating the huge corn followed by little corn. For that he has to find large and small corns to eat. Consider numbers instead of corns. Can you find the largest and smallest one?

    • CODING ARENA
    • #include <stdio.h>

    int main()

    {

      int a[50],i,n,l,s;

      scanf("%d",&n);

      for(i=0;i<n;i++)

        scanf("%d",&a[i]);

      l=s=a[0];

      for(i=1;i<n;++i)

      {

        if(a[i]>l)

           l=a[i];

        if(a[i]<s)

           s=a[i];

      }

           printf("%d",l);

           printf("\n%d",s);

     return 0;

    }

    • Test Case 1


    Input (stdin)

    5

     

    1 8 9 7 5

     

    Expected Output

    9

     

    1

    • Test Case 2


    Input (stdin)

    4

     

    9 19 7 8

     

    Expected Output

    19

     

    7

    ASCII Name

    • Problem Description


    Write a program which reads your name from the keyboard and output a list of ANCII codes, which represent your name

    • CODING ARENA
    • #include <stdio.h>

    int main()

    {

      char name[50];

      int j=0;

      scanf("%s",name);

      while(name[j]!='\0')

      {

        printf(" %d",name[j]);

        j++;

      }

     return 0;

    }

    • Test Case 1


    Input (stdin)

    SRMUNIVERSITY

     

    Expected Output

    83 82 77 85 78 73 86 69 82 83 73 84 89

    • Test Case 2


    Input (stdin)

    srm

     

    Expected Output

    115 114 109

    Multiplication Table

    • Problem Description


    Veena telling tables to her friend saradha, for every no of saradha veena telling tables upto 5,
    help to her to write code to solve the task.
    Input Method

    Integer ranges from 1 to 999

    Output Method

    Multiplication table upto 5

    • CODING ARENA::
    • #include <stdio.h>

    struct table

      {

      int a; 

      }t;

    int main()

    {

      scanf("%d",&t.a); 

      printf("1*%d=%d\n",t.a,1*t.a);

      printf("2*%d=%d\n",t.a,2*t.a);

      printf("3*%d=%d\n",t.a,3*t.a);

      printf("4*%d=%d\n",t.a,4*t.a);

      printf("5*%d=%d\n",t.a,5*t.a);

     return 0;

    }

    • Test Case 1


    Input (stdin)

    5

     

    Expected Output

    1*5=5

     

    2*5=10

     

    3*5=15

     

    4*5=20

     

    5*5=25

    • Test Case 2


    Input (stdin)

    10

     

    Expected Output

    1*10=10

     

    2*10=20

     

    3*10=30

     

    4*10=40

     

    5*10=50

    Pointers – 10

    • Problem Description


    Write a program to add two integers using functions use call by address technique of passing parameters and also illustrate the concept of pointer variables can be used to access the strings.

    Input and Output Format:

    Refer sample input and output for formatting specification.

    All float values are displayed correct to 2 decimal places.

    All text in bold corresponds to input and the rest corresponds to output.

    • CODING ARENA
    • #include <stdio.h>

    int main()

    {

      int a,b;

      scanf("%d%d",&a,&b);

      printf("The sum of the numbers is %d",a+b);

      printf("\nAccessing a string using pointer");

      printf("\nHello");



     return 0;

    }

    • Test Case 1


    Input (stdin)

    6

     

    7

     

    Expected Output

    The sum of the numbers is 13

     

    Accessing a string using pointer

     

    Hello

    • Test Case 2


    Input (stdin)

    9

     

    10

     

    Expected Output

    The sum of the numbers is 19

     

    Accessing a string using pointer

     

    Hello

    Semester Holidays

    • Problem Description


    Normally in all engineering colleges, there will be long vacation after every even semester and a short vacation after every odd semester.

    Input format:

    Input consists of 1 integers which corresponds to the current semester of the students (i.e) Even semester " Long Vacation" 
    ODD semester "Short Vacation" determine by dividing(modulo) with 2

    Output format:

    Output consists of the string "Long Vacation " or "Short Vacation".

    Refer sample input and output for further formatting specifications.

    • CODING ARENA
    • #include <stdio.h>

    int main()

    {

      int n;

      scanf("%d",&n);

      if(n%2==0)

        printf("Long Vacation");

      else 

        printf("Short Vacation");

     



     return 0;

    }

    • Test Case 1


    Input (stdin)

    6

     

    Expected Output

    Long Vacation

    • Test Case 2


    Input (stdin)

    3

     

    Expected Output

    Short Vacation

    Lucy

    • Problem Description


    Lucy is celebrating her 15th birthday. Her father promised her that he will buy her a new computer on her birthday if she solves the question asked by him. He asks Lucy to find whether the year on which she had born is leap year or not. Help her to solve this puzzle so that she celebrates her birthday happily. If her birth year is 2016 and it is a leap year display 2016 is a leap year.? Else display 2016 is not a leap year and check with other leap year conditions.

    • CODING ARENA
    • #include <stdio.h>

    int main()

    {

      int year;

      scanf("%d",&year);

      if(year%400==0)

      {

        printf("%d is a leap year",year);

      }

      else if(year%100==0)

      {

        printf("%d is not a leap year",year);

      }

      else if(year%4==0)

      {

        printf("%d is a leap year",year);

      }

      else

      {

        printf("%d is not a leap year",year);

      }

      return 0;

    }

        





     

    • Test Case 1


    Input (stdin)

    1900

     

    Expected Output

    1900 is not a leap year

    • Test Case 2


    Input (stdin)

    2016

     

    Expected Output

    2016 is a leap year

    Magic Square

    • Problem Description


    A magic square is an arrangement of numbers (usually integers) in a square grid, where the numbers in each row, and in each column, and the numbers in the forward and backward main diagonals, all add up to the same number


    Input Format:

    The input consists of (n*n+1) integers. The first integer corresponds to the number of rows/columns in the matrix. The remaining integers correspond to the elements in the matrix. The elements are read in rowwise order, first row first, then second row and so on. Assume that the maximum value of m and n is 5.

    • CODING ARENA
    • #include <stdio.h>

    int main()

    {

      int size=3;

      int a[3][3];

      int row,column=0;

      int sum,sum1,sum2;

      int flag=0;

      for(row=0;row<size;row++)

      {

        for(column=0;column<size;column++)

          scanf("%d",&a[row][column]);

      }

      sum=0;

      for(row=0;row<size;row++)

      {

        for(column=0;column<size;column++)

        {

          if(row==column)

            sum=sum+a[row][column];

        }

      }

      for(column=0;column<size;column++)

      {

        sum1=0;

        for(column=0;column<size;column++)

        {

          sum1=sum1+a[row][column];

        }

        if(sum==sum1)

          flag=1;

        else

        {

          flag=0;

          break;

        }

      }

      for(row=0;row<size;row++)

      {

        sum2=0;

        for(column=0;column<size;column++)

        {

          sum2=sum2+a[column][row];

        }

        if(sum==sum2)

          flag=1;

        else

        {

          flag=0;

          break;

        }

      }

      if(flag==1)

        printf("Magic Square");

      else

        printf("Not a Magic Square");

      return 0;

    }

        

        

    • Test Case 1


    Input (stdin)

    4 9 2

     

    3 5 7

     

    9 3 5

     

    Expected Output

    Not a Magic Square

    • Test Case 2


    Input (stdin)

    4 9 2

     

    3 5 7

     

    8 1 6

     

    Expected Output

    Magic Square

    Leave a Reply

    Back to Top