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.
Table of Content
- Better or not
- IO 19
- Sita out
- IO 35
- Fact is Fact
- Print Prime Numbers
- Roman Tour
- Read Data on a Regular Basis
- ATM Transaction
- Newton Scientist
- Differenzia
- Calculating Gain Percentage
- Units of Time
- Greedy Puppy
- Quotient Remainder
- Counting and Summing
- Bus Ticket
- Wind Chill
- Swap First and Last Digit
- For Loop Processing
- Pattern 6
- Duplicate Detection
- Print 8- Count and Sum of Even and Odd Numbers
- Letters Cyclic Shift
- Increment and Output
- Array Transformation
- Tri-Hexagonal Puzzle
- Sum of Positive Numbers
- Maximum Element
- Mr. Wireless
- Previous Character
- W String
- Lapindrome
- Concatenate Code
- Word Index 1
- String Compare
- Remove Index String 1
- Random Order
- Getting Bits
- Array Mode
- Prime Numbers Between Two Integers
- Sum of 2 Arrays using Functions
- Day and Time
- Student Management Array of Structure
- Nested Structure – Details of Student
- Printing Names
- Sum the Numbers using Union and Structures
- Multiply by 5
- Simple Structures
- Transformation
- Time Difference
- Sum of Even and Odd Numbers
- Structures – 1 Students Details
- Lower Triangular Matrix
- Front and Back
- Printing Next
- Fencing the Ground
- Alphabets
- Pointer – 4
- Bottle Deposits
- Biggest of three Numbers
- Twos Mod
Better or Not
- Problem Description
One criteria for evaluating 2 different colleges is based on the student strength.
Write a program to compare 2 colleges based on the student strength.
Input Format:
Input consists of 2 integers. The first integer corresponds to the number of students in college 1 and the second integer corresponds to the number of students in college 2.
Output Format:
Output consists of the string College 1 is better or College 2 is better.
Refer sample input and output for further formatting specifications.
Sample Input and Output:
[All text in bold corresponds to input and the rest corresponds to output]
- CODING ARENA::
- #include
int main()
{
int a,b;
scanf("%d %d",&a,&b);
if(a>b)
{
printf("College 1 is better");
}
else
{
printf("College 2 is better");
}
return 0;
}
- Test Case 1
Input (stdin)
1000
2000
Expected Output
College 2 is better
- Test Case 2
Input (stdin)
2001
1999
Expected Output
College 1 is better
IO 19
- Problem Description
Heera is a cute little gal of age 5 years old, she had one piggybank to save money (coins). Her piggy bank got full and she was excited to her savings money. So, she classified the coins of its followings types , Rs.10 coins, Rs. 5 Coins , Rs .2 Coins, Rs. 1 Coins. Now Please help her to calculate the total amount she saved?
Input :
total number of coins collected on every classified type respectively( Rs..10 Coins, Rs. 5 Coins, Rs. 2 coins, Rs.1 Coins)
- CODING ARENA::
- #include <stdio.h>
int main()
{
int a, b, c, d, e;
scanf("%d %d %d %d %d",&a, &b, &c, &d, &e);
a=a*10;
b=b*5;
c=c*2;
d=d*1;
e=a+b+c+d;
printf("Total amount in the piggybank=%d.00", e);
return 0;
}
- Test Case 1
Input (stdin)
10
23
43
6
Expected Output
Total amount in the piggybank=307.00
- Test Case 2
Input (stdin)
8
33
4
1
Expected Output
Total amount in the piggybank=254.00
Sita out
- Problem Description
Ms. Sita, the faculty handling programming lab for you is very strict. Your seniors have told you that she will not allow you to enter the week's lab if you have not completed atleast half the number of problems given last week.
Many of you didn't understand this statement and so they requested the good programmers from your batch to write a program to find whether a student will be allowed into a week's lab given the number of problems given last week and the number of problems solved by the student in that week.
Can you help in writing this program?
Input Format:
Input consists of 2 integers. The first integer corresponds to the number of problems given and the second integer corresponds to the number of problems solved.
Output Format:
Output consists of the string IN or OUT.
Refer sample input and output for further formatting specifications.
- CODING ARENA
- #include <stdio.h>
int main()
{
int a,b,c;
scanf("%d",&a);
scanf("%d",&b);
c=a/2;
if(b>=c)
{
printf("IN");
}
else
{
printf("OUT");
}
return 0;
}
- Test Case 1
Input (stdin)
8 3
Expected Output
OUT
- Test Case 2
Input (stdin)
8 4
Expected Output
IN
IO 35
- Problem Description
Write a program to display a grocery bill of the product purchased in the small market by Vijay. Get the following details from Vijay:
Get the product name
Get the price of the product(Price per Unit)
Get the quantity of the product purchased
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 ch[500];
float f,p;
int u;
scanf("%s",ch);
scanf("%f",&f);
scanf("%d",&u);
printf("Product Details\n");
printf("%s\n",ch);
printf("%.2f\n",f);
printf("%d\n",u);
p=f*u;
printf("Bill:%.2f",p);
return 0;
}
Test Case 1
Input (stdin)
soap
33.00
2
Expected Output
Product Details
soap
33.00
2
Bill:66.00
Test Case 2
Input (stdin)
chocolate
11.11
5
Expected Output
Product Details
chocolate
11.11
5
Bill:55.55
Fact is Fact
Problem Description
Dolu have a homework to find sum of factors of a given number. Use C language to solve Dolus Problem
CODING ARENA::
#include <stdio.h>
int main()
{
int sum,n=1,a;
scanf("%d",&a);
if(a==0)
printf("0");
while(n<=a)
{
if(a!=0 && a%n==0)
{
printf("%d ",n);
sum=sum+n;
}
n=n+1;
}
printf("\nSum=%d",sum);
return 0;
}
Test Case 1
Input (stdin)
25
Expected Output
1 5 25
Sum=31
Test Case 2
Input (stdin)
45
Expected Output
1 3 5 9 15 45
Sum=78
Print Prime Numbers
- Problem Description
Ravi is poor in mathematics; his teacher wants him to improve his problem solving skills. So he gives a number to Ravi and asked him to find the prime numbers between 2 and the given number.
- CODING ARENA
- #include <stdio.h>
int main()
{
int n,i,fact,j;
scanf("%d",&n);
for(i=3;i<n;i++)
{
fact=0;
for(j=1;j<n;j++)
{
if(i%j==0)
fact++;
}
if(fact==2)
printf("%d ",i);
}
return 0;
}
- Test Case 1
Input (stdin)
11
Expected Output
3 5 7
- Test Case 2
Input (stdin)
17
Expected Output
3 5 7 11 13
Roman Tour
- Problem Description
Rafiq trying to convert roman to numbers. He asks maths teacher to know about the conversion. His maths teacher explained the conversion of roman to numbers. Then Rafiq understands the conversion concepts, by using that he write a C program to do conversion.
Valid digits are I, V, X, L, C, D, M
- CODING ARENA
- #include <stdio.h>
#include<string.h>
int digit(char);
int main()
{
char rom[30];
int a[30],l,i,k,dec;
scanf("%s",rom);
l=strlen(rom);
for(i=0;i<l;i++)
{
switch(rom[i])
{
case 'I':a[i]=1;
break;
case 'V':a[i]=5;
break;
case 'X':a[i]=10;
break;
case 'L':a[i]=50;
break;
case 'C':a[i]=100;
break;
case 'D':dec=dec+500;
break;
case 'M':a[i]=1000;
break;
default:printf("Invalid choice");
break;
}
}
k=a[l-1];
for(i=l-1;i>0;i–)
{
if(a[i]>a[i-1])
{
k=k-a[i-1];
}
if(a[i]<=a[i-1])
{
k=k+a[i-1];
}
}
printf("%d",k);
return 0;
}
- Test Case 1
Input (stdin)
X
Expected Output
10
- Test Case 2
Input (stdin)
XIV
Expected Output
14
Read data on a regular basis
- PROBLEM DESCRIPTION
- "Alexey is trying to develop a program for a very simple microcontroller. It makes readings from various sensors over time, and these readings must happen at specific regular times. Unfortunately, if two of these readings occur at the same time, the microcontroller freezes and must be reset.
There are N different sensors that read data on a regular basis. For each i from 1 to N, the reading from sensor i will occur every Ai milliseconds with the first reading occurring exactly Ai milliseconds after the microcontroller is powered up. Each reading takes precisely one millisecond on Alexey's microcontroller.
Alexey wants to know when the microcontroller will freeze after he turns it on.
Input
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line contains single integer N denoting the number of sensors.
The second line contains N space-separated integers A1, A2, …, AN denoting frequency of measurements. Namely, sensor i will be read every Ai milliseconds with the first reading occurring Ai milliseconds after the microcontroller is first turned on.
Output
For each test case, output a single line containing the number of milliseconds until the microcontroller freezes.
Constraints
1< T< 10
2< N < 500
1< Ai < 109" - CODING ARENA
- #include <stdio.h>
int gcd(int u,int v)
{
long int t,a=u,b=v,ans;
while(u>0)
{
if(u<v)
{
t=u;
u=v;
v=t;
}
u=u-v;
}
ans=(a*b)/v;
return ans;
}
int main()
{
int test,z;
scanf("%d",&test);
for(z=0;z<test;z++)
{
int n,i,j;
scanf("%d",&n);
int num[n],ans=1000000000;
for(i=0;i<n;i++)
{
scanf("%d",&num[i]);
}
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
long int temp=gcd(num[i],num[j]);
if(temp<ans)
ans=temp;
}
}
printf("%d\n",ans);
}
return 0;
}
- Test Case 1
Input (stdin)
3
3
2 3 5
4
1 8 7 11
4
4 4 5 6
Expected Output
6
7
4
- Test Case 2
Input (stdin)
3
3
1 3 5
4
1 8 7 11
5
4 4 5 6 12
Expected Output
3
7
4
ATM Transaction
- Problem Description
Mahesh would like to withdraw X from an ATM. The cash machine will only accept the transaction if X is a multiple of 5, and Mahesh account balance has enough cash to perform the withdrawal transaction (including bank charges). For each successful withdrawal the bank charges 0.50. Calculate Mahesh account balance after an attempted transaction.
Input
Positive integer 0 < X <= 2000 – the amount of cash which Mahesh wishes to withdraw.
Nonnegative number 0<= Y <= 2000 with two digits of precision – Mahesh initial account balance.
Output
Output the account balance after the attempted transaction, given as a number with two digits of precision. If there is not enough money in the account to complete the transaction, output the current bank balance.
Example – Successful Transaction
Input:
30 120.00
Output:
89.50
Example – Incorrect Withdrawal Amount (not multiple of 5)
Input:
42 120.00
Output:
120.00
Example – Insufficient Funds
Input:
300 120.00
Output:
120.00
- CODING ARENA
- #include <stdio.h>
int main()
{
int a;
float b,c;
scanf("%d%f",&a,&b);
if(a!=0 && a%5==0 && a<b)
{
c=b-(0.50+a);
printf("%.2f",c);
}
else
printf("%.2f",b);
return 0;
}
- Test Case 1
Input (stdin)
30 120.00
Expected Output
89.50
- Test Case 2
Input (stdin)
42 120.00
Expected Output
120.00
Newton Scientist
- Problem Description
Newton was one of the great scientist. The Indian council decided that we need to assign some number as a gift to the great scientist.
There was a suggestion given by the Indian Council. If the number is divided by 1 and by itself that they can assign the number to the great scientist.
Kindly help the Indian Council to complete the task by writing a simple logic.
Refer sample Input and Output:
Input 1: 13
Output: Give to Scientist Newton
Input 2: 25
Output: Dont Give to Scientist Newton
- CODING ARENA
- #include <stdio.h>
int main()
{
int n,i,flag=0;
scanf("%d",&n);
for(i=2;i<=n/2;i++)
{
if(n%i==0)
{
flag=1;
break;
}
}
if(flag==0)
printf("Give to Scientist Newton");
else
printf("Dont Give to Scientist Newton");
return 0;
}
- Test Case 1
Input (stdin)
13
Expected Output
Give to Scientist Newton
- Test Case 2
Input (stdin)
10
Expected Output
Dont Give to Scientist Newton
Differenzia
- Problem Description
In a country named Differenzia the minors and senior citizens are not eligible to vote. Only people aged between 18 to 60 (both inclusive) are eligible to vote. Write a program to determine a person in Differenzia is eligible to vote.
- CODING ARENA::
- #include <stdio.h>
int main()
{
int a;
scanf("%d",&a);
if(a>=18 && a<=60)
printf("Eligible");
else
printf("Not Eligible");
return 0;
}
- Test Case 1
Input (stdin)
18
Expected Output
Eligible
- Test Case 2
Input (stdin)
17
Expected Output
Not Eligible
Calculating Gain Percentage
- Problem Description
SRM University buys an old scooter for Rs. A and Spends Rs. B on its repairs. if he sells the scooter for Rs.C , what is his gain %? Write C program to compute the gain %?
Input format:
The first input is an integer which corresponds to A . The second input is an integer which corresponds to B. The third input is a float which corresponds to gain $
- CODING ARENA
- #include <stdio.h>
int main()
{
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
printf("The gain percentage is=%0.2f",((c-a-b)*1.0/(a+b))*100);
return 0;
}
- Test Case 1
Input (stdin)
4700
800
5800
Expected Output
The gain percentage is=5.45
- Test Case 2
Input (stdin)
5000
700
5800
Expected Output
The gain percentage is=1.75
Units of time
- Problem Description
Develop a program that begins by reading a number of seconds from the user.
Then your program should display the equivalent amount of time in the form D:HH:MM:SS, where D, HH, MM, and SS represent days, hours, minutes and seconds respectively.
The hours, minutes and seconds should all be formatted so that they occupy exactly two digits, with a leading 0 displayed if necessary.
- CODING ARENA::
- #include <stdio.h>
int main()
{int a;
int d,m,s,h;
scanf("%d",&a);
if(a>0)
{
d=a/(24*3600);
h=(a%(24*3600))/3600;
m=(a%3600)/60;
s=(a%3600)%60;
printf("The Duration is %d days %d hours %d minutes %d seconds",d,h,m,s);
}
else
{
printf("0");
}
return 0;
}
- Test Case 1
Input (stdin)
563685
Expected Output
The Duration is 6 days 12 hours 34 minutes 45 seconds
- Test Case 2
Input (stdin)
0
Expected Output
0
Greedy Puppy
- Problem Description
Tuzik is a little dog. But despite the fact he is still a puppy he already knows about the pretty things that coins are. He knows that for every coin he can get very tasty bone from his master. He believes that some day he will find a treasure and have loads of bones.
And finally he found something interesting. A wooden chest containing N coins! But as you should remember, Tuzik is just a little dog, and so he cant open it by himself. Actually, the only thing he can really do is barking. He can use his barking to attract nearby people and seek their help. He can set the loudness of his barking very precisely, and therefore you can assume that he can choose to call any number of people, from a minimum of 1, to a maximum of K.
When people come and open the chest they divide all the coins between them in such a way that everyone will get the same amount of coins and this amount is maximal possible. If some coins are not used they will leave it on the ground and Tuzik will take them after they go away. Since Tuzik is clearly not a fool, he understands that his profit depends on the number of people he will call. While Tuzik works on his barking, you have to find the maximum possible number of coins he can get.
Input
The first line of the input contains an integer T denoting the number of test cases. Each of next T lines contains 2 space-separated integers: N and K, for this test case.
Output
For each test case output one integer – the maximum possible number of coins Tuzik can get.
Constraints
1<=T<=50
1<=N, K<=105
In the first example he should call two people. Each of them will take 2 coins and they will leave 1 coin for Tuzik.
In the second example he should call 3 people
EXPLANATION :
As the size of the inputs in the problem is very small ( in the order of 10^2 ) , we can simply use brute-forcing ( Brute Forcing ) and test every possible case and print the value of the maximum coins that the dog gets.
As the dog only gets what remains after equal spitting , this can be calculated by using the modulo " % " ( Modulo ) operation .
Example :
For 2nd test case : ( 11,3 ) :
He can call maximum of 3 people
If he calls only 1 person , the person will take all the coins , leaving him with nothing
If he calls 2 people , he will be left with only 1 coin , as the two people take 5 , 5 coins each.
If he calls 3 people , each one will take 3 coins , leaving him with 2 coins
So the best case for him is to call 3 people so he can get 2 coins.
The input format is :
An integer , to represent the number of test cases ( number of times the user will provide distinct values of N and K)
Pair of integers representing N and K values respectively ( this will be the input format for next t cases )
The result will be biggest modulo value that a number gives with N , such that the number is less than K.
- CODING ARENA::
- #include <stdio.h>
int main()
{
int t,n,k;
scanf("%d",&t);
while(t–)
{
scanf("%d %d",&n,&k);
printf("%d\n",n%k);
}
return 0;
}
- Test Case 1
Input (stdin)
2
5 2
11 3
Expected Output
1
2
- Test Case 2
Input (stdin)
3
5 3
11 2
7 2
Expected Output
2
1
1
Quotient Remainder
- Problem Description
Write a C program to find the quotient and remainder for the given dividend and divisor.
- CODING ARENA
- #include <stdio.h>
int main()
{
int a,b;
scanf("%d%d",&a,&b);
printf("%d",a/b);
printf("\n%d",a%b);
return 0;
}
- Test Case 1
Input (stdin)
25
4
Expected Output
6
1
- Test Case 2
Input (stdin)
35
6
Expected Output
5
5
Counting and Summing
- Problem Description
Return the count of positives numbers and the sum of negative numbers for the given array.
- CONDING ARENA
- #include <stdio.h>
int main()
{
int a,b,i,pos,neg;
scanf("%d",&a);
for(i=0;i<a;i++)
{
scanf("%d",&b);
if(b>0)
pos=pos+1;
else
neg=neg+b;
}
printf("%d\n",pos);
printf("%d\n",neg);
return 0;
}
- Test Case 1
Input (stdin)
15
1 2 3 4 5 6 7 8 9 10 -11 -12 -13 -14 -15
Expected Output
10
-65
- Test Case 2
Input (stdin)
14
0 2 3 0 5 6 7 8 9 10 -11 -12 -13 -14
Expected Output
8
-50
Bus Ticket
Problem Description
Every day, Mike goes to his job by a bus, where he buys a ticket. On the ticket, there is a letter-code that can be represented as a string of upper-case Latin letters.
Mike believes that the day will be successful in case exactly two different letters in the code alternate. Otherwise, he believes that the day will be unlucky. Please see note section for formal definition of alternating code.
You are given a ticket code. Please determine, whether the day will be successful for Mike or not. Print ""YES"" or ""NO"" (without quotes) corresponding to the situation.
CODING ARENA::
#include <stdio.h>
int main()
{
int i,k,test,t;
char a[100],second,first;
scanf("%d",&t);
while(t–)
{
scanf("%s",a);
k=1;
test=1;
first=a[0];
second=a[1];
if(first!=second)
{
for(i=2;a[i]!='\0';i++)
{
if(k)
{
if(a[i]!=first)
{
test=0;
break;
}
k=0;
}
else
{
if(a[i]!=second)
{
test=0;
break;
}
k=1;
}
}
if(test==0)
printf("NO\n");
else
printf("YES\n");
}
else
printf("NO\n");
}
return 0;
}
Test Case 1
Input (stdin)
2
ABAB
AB
Expected Output
YES
YES
Test Case 2
Input (stdin)
1
ACAC
Expected Output
YES
Wind Chill
- Problem Description
When the wind blows in cold weather, the air feels even colder than it actually is because the movement of the air increases the rate of cooling for warm objects, like people. This effect is known as wind chill.
In 2016, Jammu and Kashmir, the Delhi and the Himachal Pradesh adopted the following formula for computing the wind chill index. Within the formula Ta is the air temperature in degrees Celsius and V is the wind speed in kilometers per hour.
A similar formula with different constant values can be used with temperatures in degrees Fahrenheit and wind speeds in miles per hour.
WCI = 13.12 + 0.6215Ta – 11.37V power 0.16 + 0.3965Ta V power 0.16
Write a program that begins by reading the air temperature and wind speed from then user. Once these values have been read your program should display the wind chill index rounded to the closest integer. The
- CODING ARENA
- #include <stdio.h>
#include <math.h>
int main()
{
float a,b,p,wcl;
scanf("%f %f",&a,&b);
p=pow(b,0.16);
wcl=13.12+(0.6215*a)-(11.37*p)+(0.3965*a*p);
printf("Windchill is %.2f",wcl);
return 0;
}
- Test Case 1
Input (stdin)
39.2
61.1
Expected Output
Windchill is 45.54
- Test Case 2
Input (stdin)
0
Expected Output
0
Swap first and last digit
- Problem Description
John has a task to swap the first and last digit of the given number. Help him to write a C program to input any number from user and swap the first and last digit of the number
- CODING ARENA
- #include <stdio.h>
#include <math.h>
int main()
{
int num,first,count,last,a,b,snum;
scanf("%d",&num);
count=log10(num);
first=num/pow(10,count);
last=num%10;
a=first*(pow(10,count));
b=num%a;
num=b/10;
snum=last*(pow(10,count))+(num*10+first);
printf("%d",snum);
return 0;
}
- Test Case 1
Input (stdin)
12345
Expected Output
52341
- Test Case 2
Input (stdin)
82341
Expected Output
12348
For loop processing
- Problem Description
Program to calculate the sum of first n natural numbers
- CODING ARENA::
- #include <stdio.h>
int main()
{
int n,i,sum=0;
scanf("%d",&n);
for(i=1;i<=n;i++)
{
sum=sum+i;
}
printf ("%d",sum);
return 0;
}
- Test Case 1
Input (stdin)
10
Expected Output
55
- Test Case 2
Input (stdin)
5
Expected Output
15
Pattern 6
- Problem Description
Write a program to generate a following numbers structure
- CODING ARENA
- #include
int main()
{
int num,r,c;
scanf("%d",&num);
for(r=1;num>=r;r++)
{
for(c=1;c<=num;c++)
printf("%d",c);
printf("\n");
}
return 0;
}
- Test Case 1
Input (stdin)
5
Expected Output
12345
12345
12345
12345
12345
- Test Case 2
Input (stdin)
3
Expected Output
123
123
123
Duplicate detection
- Problem Description
Jim was looking after a Given array which is already sorted. She found that it has duplicate elements. Your task is to help joyce by writing a program to display the duplicate element(s) present in the array.
- CODING ARENA
- #include <stdio.h>
int main()
{
int a[100],i,j,n;
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[j]==a[i])
{
printf("%d ",a[i]);
}
}
}
return 0;
}
- Test Case 1
Input (stdin)
5
5 4 2 2 5
Expected Output
5 2
- Test Case 2
Input (stdin)
4
55 66 99 99
Expected Output
99
Print 8 – Count and sum of even and odd numbers
- Problem Description
Write a C program to find the sum of odd numbers and sum of even numbers from 1 to N. Output the computed sums on two different lines with suitable headings
(Inclusive of both positive and negative numbers)
Input format:
Input consists of n+1 integers. The first integer corresponds to n and the next n integers correspond to the numbers to be added. Consider 0 to be a positive number
Example 1:
Input: 10
Output:
Odd=25
(1+3+5+7+9) = 25
Even=30
(2+4+6+8+10)=30
If the input number is odd then the user should throw the message as "Wrong Input"
Example 2:
Input : 11
Output=Wrong Input
- CODING ARENA
- #include <stdio.h>
int main()
{
int n,t=0,f=0;
scanf("%d",&n);
if(n%2!=0)
{
printf("Wrong Input");
}
else
{
n=n+1;
while(n–)
{
if(n%2==0)
{
t=t+n;
}
else
{
f=f+n;
}
}
printf("Sum of all odd numbers=%d\n",f);
printf("Sum of all even numbers=%d",t);
}
return 0;
}
- Test Case 1
Input (stdin)
10
Expected Output
Sum of all odd numbers=25
Sum of all even numbers=30
- Test Case 2
Input (stdin)
19
Expected Output
Wrong Input
Letters Cyclic Shift
- Problem Description
"You are given a non-empty string s consisting of lowercase English letters. You have to pick exactly one non-empty substring of s and shift all its letters 'z' 'y' 'x' 'b' 'a' 'z'. In other words, each character is replaced with the previous character of English alphabet and 'a' is replaced with 'z'.
What is the lexicographically minimum string that can be obtained from s by performing this shift exactly once?
Input
The only line of the input contains the string s (1<|s|<100000) consisting of lowercase English letters.
Output
Print the lexicographically minimum string that can be obtained from s by shifting letters of exactly one non-empty substring.
Note
String s is lexicographically smaller than some other string t of the same length if there exists some 1i|s|, such that s1=t1,s2=t2,…,si-1=ti-1, and si<ti."
- CODING ARENA
- #include <stdio.h>
#include <string.h>
int main()
{
char s[100001];
int i,k=0;
scanf("%s",s);
//l=strlen(a);
for(i=0;s[i]!='\0';i++)
if(s[i]!='a')
break;
for(;s[i]!='\0';i++)
{
if(s[i]=='a')
break;
s[i]–;
k++;
}
if(!k)
s[strlen(s)-1]='z';
puts(s);
return 0;
}
/*
int main()
{
char *shiftstr(char str[],int offset)
{
unsigned int i;
for(i=0;str!='\0';i++)
{
str[i]+=offset;
}
return str;
}
return 0;
}*/
- Test Case 1
Input (stdin)
codeforces
Expected Output
bncdenqbdr
- Test Case 2
Input (stdin)
srmulc
Expected Output
rqltkb
Increment And Output
- Problem Description
Get a n value from the user and print 1 to n and again print in reverse as n-1 to 1 as output using increment and decrement operator.
- CODING ARENA::
- #include <stdio.h>
int main()
{
int n,i,j;
scanf("%d",&n);
for(i=1;i<=n;i++)
{
printf ("%d ",i);
}
for(j=n-1;j>0;j–)
printf ("%d ",j);
return 0;
}
- Test Case 1
Input (stdin)
15
Expected Output
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1
- Test Case 2
Input (stdin)
6
Expected Output
1 2 3 4 5 6 5 4 3 2 1
Array Transformation
- Problem Description
"Given n numbers, you can perform the following operation any number of times : Choose any subset of the numbers (possibly empty), none of which are 0. Decrement the numbers in the subset by 1, and increment the numbers not in the subset by K.
Is it possible to perform operations such that exactly n – 1 numbers become 0 ?
- CODING ARENA
- #include <stdio.h>
int main()
{
int t,n,k,a[100],hash[1000],i,ans,x;
scanf("%d",&t);
while(t–)
{
scanf("%d %d",&n,&k);
for(i=0;i<1000;i++)hash[i]=0;
ans=0;
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
x=(a[i]%(k+1));
hash[x]++;
if(hash[x]>n-2)ans=1;
}
if(ans)
printf("YES\n");
else
printf("NO\n");
}
return 0;
}
- Test Case 1
Input (stdin)
3
2 1
10 10
3 2
1 2 2
3 2
1 2 3
Expected Output
YES
YES
NO
- Test Case 2
Input (stdin)
3
2 1 4
3 2 4
1 2 2
3 2 3
1 2 4 4
Expected Output
YES
YES
YES
Tri-Hexagonal Puzzle
- Problem Description
"Little Johnny wants to play with his friends today. But his babysitter won't let him go! After a lot of begging, the heartless nanny gives him her brand new electronic puzzle and says: ""If you solve the puzzle then you are free to go"". Not being aware of Little Johnny's IT skills, the nanny leaves the kid alone.
Rapidly, Little Johnny sends you an e-mail asking for your help.
The puzzle consists of three hexagons as shown in the figure. Each vertex is painted black or white. Some of them belong to just one hexagon and some of them belong to more than one. Exactly four of them are painted black, and the other nine are white. The goal is to make the shared vertexes black by means of allowed moves: rotating a hexagon 60 degrees clockwise or counter-clockwise.
Can you help Little Johnny?
Input
Input starts with an integer T, the number of puzzles to solve (1<=T<=100). T lines follow, each one having 13 binary digits, corresponding to the top-down, left to right labeling of the vertexes in the puzzle. A '0' means the i-th vertex is painted white, while a '1' means it is painted black.
Output
For each test case output M on a single line, the minimum number of moves required to solve the puzzle. Then print M lines, each one describing a move in the following manner: two space separated integers H and C, the rotated hexagon (upper left is 0, upper right is 1, lower one is 2) and the direction (0 for counter-clockwise, 1 for clockwise).
If there is more than one solution, any will suffice.
- CODING AREA::
- #include <stdio.h>
#define MX 13
#define NS 715
int se[NS],pi[NS],pm[NS],cu,n;
char pu[MX+1];
const int bi[]={1,2,4,8,16,32,64,128,256,512,1024,2048,4096};
const int mo[6][7]={{10,12,9,6,4,7,10},{10,7,4,6,9,12,10},{5,3,6,9,11,8,5},{5,8,11,9,6,3,5},{4,6,3,1,0,2,4},{4,2,0,1,3,6,4}};
const int go=0x258;
int f1(int m,int p)
{
int c=p,i=0;
for(;i++<6;c=((p&bi[mo[m][i]]))?(c|bi[mo[m][i-1]]):(c&(~bi[mo[m][i-1]])));
return c;
}
int f2(int c)
{
int i;
for(i=cu-1;i>=0;i–)
if(c==se[i])
return i;
return -1;
}
int f3(char p[])
{
int i=0,s=0;
for(;i<MX;s=(p[i]=='1')?(s|bi[MX-i-1]):s,i++);
return s;
}
void f4(int s)
{
int i=0,j,p[12],in=f2(s);
for(;in;p[i++]=pm[in],in=pi[in]);
for(printf("%d\n",i+(j=0));j++<i;printf("%d %d\n",(p[j-1]>>1),(p[j-1]%2)));
}
int main()
{
int fall,p=0,m,c;
for(se[!(cu=1)]=go;p<cu;p++)
for(m=0;m<6;m++)
if(f2(c=f1(m,se[p]))==-1)
{
se[cu]=c;
pi[cu]=p;
pm[cu++]=m^0x1;
}
for(scanf("%d",&fall);fall–;)
{
scanf("%s",pu);
f4(f3(pu));
}
return 0;
}
- Test Case 1
Input (stdin)
1
0000000101011
Expected Output
3
2 0
2 0
1 1
- Test Case 2
Input (stdin)
1
0001000100011
Expected Output
4
2 0
2 0
0 1
1 1
Sum of positive numbers
- Problem Description
Write a program to find the sum of positive numbers in an array.
Input Format:
Input consists of n+1 integers. The first integer corresponds to n , the size of the array. The next ?n? integers correspond to the elements in the array. Assume that the maximum value of n is 15.
Output Format:
Refer sample output for details
- CODING ARENA
- #include <stdio.h>
int main()
{
int num,a[100],sum=0,i;
scanf("%d",&num);
for(i=0;i<num;i++)
scanf("%d",&a[i]);
for(i=0;i<num;i++)
{
if(a[i]>=0)
{
sum=sum+a[i];
}
}
printf("sum=%d",sum);
return 0;
}
- Test Case 1
Input (stdin)
5
2 3 6 8 -1
Expected Output
sum=19
- Test Case 2
Input (stdin)
5
-1 -2 -3 -4 -5
Expected Output
sum=0
Maximum Element
- Problem Description
Display Largest Element of an array
- CODING ARENA::
- #include <stdio.h>
int main()
{
int a[10],n,j,i,temp;
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<n;i++)
{
for (j=0;j<n;j++)
{
if(a[i]<a[j])
{
a[i]=temp;
a[i]=a[j];
temp=a[j];
}
}
}
printf ("%d",a[n-1]);
return 0;
}
- Test Case 1
Input (stdin)
5
1 2 3 4 54
Expected Output
54
- Test Case 2
Input (stdin)
8
1 2 3 55 123 2 1 99
Expected Output
123
Mr. Wireless
- Problem Description
"Mr. Wire Less is not that good at implementing circuit in a breadboard. In his Digital Logic Design course, he has to implement several boolean functions using the breadboard. In a breadboard, inputs are given through the switches and outputs are taken through the LEDs. Each input switch can be either in ground state or in high state. So, if he wishes to implement a boolean function, f(x1, x2, .., xn) that takes n boolean values as input and returns m boolean values as output, he will use n switches and m LEDs.
Mr. Wire Less can quickly assemble the necessary ICs and wires, but the key problem is testing. While testing he has to check with all possible input combination, to make sure whether the output of LED corresponds to the expected output or not. This is taking too long for him, as most of the switches are jammed and difficult to toggle.
Mr. Wire Less is asking for help to minimize his time of testing. So, your task is to minimize the total number of switch-toggle throughout the testing.
For example, if Mr. Wire Less has to test a function f(x0, x1) of two variables, he may choose this switching-sequence for testing 00, 11, 10, 01. In this case, the total number of switch-toggle will be 2+1+2 = 5. But if he tests in this sequence 00, 10, 11, 01 total number of toggle will be 1+1+1 = 3.
Given n, you have to output the minimum number of toggle needed for complete testing. Though it seems impractical, he wants you to solve the problem for a very large value of n. But, then the toggle value can be quite big. So, he is completely okay with the toggle value modulo 8589934592 (233).
"
- CODING ARENA::
- #include<stdio.h>
#include<math.h>
int main()
{
int n,i;
scanf("%d",&n);
long long int m,l;
for(i=1;i<=n;i++)
{
scanf("%lld",&m);
if(m<=33)
{
l=(long long int)(pow(2,m)-1);
printf("Case %d: %lld\n",i,l);
}
else
printf("Case %d: 8589934591\n",i);
}
return 0;
}
- Test Case 1
Input (stdin)
2
1
2
Expected Output
Case 1: 1
Case 2: 3
- Test Case 2
Input (stdin)
3
2
3
Expected Output
Case 1: 3
Case 2: 7
Case 3: 7
Previous Character
- Problem Description
Latha and Trisha are friends. They love to play with words. Ishu gives them a task to replace each characters in a string with its previous letter. Can you help them to complete this task?
- CODING ARENA
- #include <stdio.h>
#include <string.h>
int main()
{
int a[100],i,l;
char s1[100];
scanf("%s",s1);
l=strlen(s1);
for(i=0;i<l;i++)
{
a[i]=s1[i];
a[i]=a[i]-1;
s1[i]=a[i];
}
printf("%s",s1);
return 0;
}
- Test Case 1
Input (stdin)
bcd
Expected Output
abc
- Test Case 2
Input (stdin)
bqqb
Expected Output
appa
W String
- Problem Description
Kira likes to play with strings very much. Moreover he likes the shape of W very much. He takes a string and try to make a W shape out of it such that each angular point is a # character and each sides has same characters. He calls them W strings.
For example, the W string can be formed from "aaaaa#bb#cc#dddd" such as:
a
a d
a # d
a b c d
a b c d
# #
He also call the strings which can generate a W shape (satisfying the above conditions) W strings.
More formally, a string S is a W string if and only if it satisfies the following conditions (some terms and notations are explained in Note, please see it if you cannot understand):
The string S contains exactly 3 # characters. Let the indexes of all # be P1 < P2 < P3 (indexes are 0-origin).
Each substring of S[0, P11], S[P1+1, P21], S[P2+1, P31], S[P3+1, |S|1] contains exactly one kind of characters, where S[a, b] denotes the non-empty substring from a+1th character to b+1th character, and |S| denotes the length of string S (See Note for details).
Now, his friend Ryuk gives him a string S and asks him to find the length of the longest W string which is a subsequence of S, with only one condition that there must not be any # symbols between the positions of the first and the second # symbol he chooses, nor between the second and the third (here the "positions" we are looking at are in S), i.e. suppose the index of the #s he chooses to make the W string are P1, P2, P3 (in increasing order) in the original string S, then there must be no index i such that S[i] = # where P1 < i < P2 or P2 < i < P3.
Help Kira and he wont write your name in the Death Note
- CODING ARENA
- #include<stdio.h>
#include<string.h>
#include<malloc.h>
//using namespace std;
void program();
char s[10003];
int *max1, *max2, *max3;
int k1=0;
void fxn(int n)
{
int x[30]={0};
int x2[30]={0};
int x3[30]={0};
int max=0,i,max_2=0,max_3=0;
int j,k=0;
for(i=0;i<n;i++)
{
//printf("%c",s[i]);
if(s[i]=='#')
{
max1[k]=max;
max2[k]= max_2;
for(j=0;j<30;j++) x2[j]=0;
max_2=0;
k++;
continue;
}
x[s[i]-'a']++;
x2[s[i]-'a']++;
if(x2[s[i]-'a']>max_2)
max_2= x2[s[i]-'a'];
if(x[s[i]-'a']>max)
max= x[s[i]-'a'];
}
k–;
k1=k;
for(i=n-1;i>=0;i–)
{
if(s[i]=='#')
{
max3[k]= max_3;
k–;
continue;
}
x3[s[i]-'a']++;
if(x3[s[i]-'a'] >max_3)
max_3= x3[s[i]-'a'];
}
}
int main()
{
int t;
scanf("%d",&t);
while(t–)
program();
return 0;
}
void program()
{
//char s[10003];
scanf("%s",s);
//int x[30]= {0};
int max=0,t,i,count=0;
//vector<int> v;
int n;
for(i=0;s[i]!='\0';i++)
{
if(s[i]=='#')
count++;
}
max1= (int*)malloc(sizeof(int)*count);
max2= (int*)malloc(sizeof(int)*count);
max3= (int*)malloc(sizeof(int)*count);
for(i=0;i<count;i++)
{
max1[i]=0;
max2[i]=0;
max3[i]=0;
}
n=strlen(s);
max=0;
fxn(n);
int a,b,c,d;
for(i=2;i<count;i++)
{
a= max1[i-2];
b= max2[i-1];
c= max2[i];
d= max3[i];
//printf("%d %d %d %d \n",a,b,c,d);
if(a!=0 && b!=0 && c!=0 && d!=0)
{
t= a+b+c+d;
if(t>max)
max=t;
}
}
if(max==0)
printf("%d\n",max);
else
printf("%d\n",max+3);
}
- Test Case 1
Input (stdin)
1
aaaaa#bb#cc#dddd
Expected Output
16
- Test Case 2
Input (stdin)
1
acb#aab#bab#accba
Expected Output
10
Lapindrome
- Lapindrome is defined as a string which when split in the middle, gives two halves having the same characters and same frequency of each character. If there are odd number of characters in the string, we ignore the middle character and check for lapindrome. For example gaga is a lapindrome, since the two halves ga and ga have the same characters with same frequency. Also, abccab, rotor and xyzxy are a few examples of lapindromes. Note that abbaab is NOT a lapindrome. The two halves contain the same characters but their frequencies do not match.
Your task is simple. Given a string, you need to tell if it is a lapindrome.
Input:
First line of input contains a single integer T, the number of test cases.
Each test is a single line containing a string S composed of only lowercase English alphabet.
Output:
For each test case, output on a separate line: "YES" if the string is a lapindrome and "NO" if it is not.
Constraints:
1 <= T <= 100
2 <= |S| <= 1000, where |S| denotes the length of S - CODING ARENA
- #include <stdio.h>
#include <string.h>
int main()
{
int ans,l,t,i,c1,c2;
char s[1001],c;
scanf("%d",&t);
while(t–)
{
ans=1;
scanf("%s",s);
char s1[1001],s2[1001];
l=strlen(s);
c1=c2=0;
for(i=0;i<l/2;i++)
s1[c1++]=s[i];
if(l%2==1)
i=l/2+1;
else
i=l/2;
for(;i<l;i++)
s2[c2++]=s[i];
s1[c1]='\0';
s2[c2]='\0';
int ar1[26],ar2[26];
memset(ar1,0,26*sizeof(int));
memset(ar2,0,26*sizeof(int));
for(i=0;i<c1;i++)
{
c=s1[i];
ar1[(int)c-97]++;
}
for(i=0;i<c2;i++)
{
c=s2[i];
ar2[(int)c-97]++;
}
for(i=0;i<26;i++)
{
if(ar1[i]!=ar2[i])
{
ans=0;
break;
}
}
if(ans==1)
printf("YES\n");
else
printf("NO\n");
}
return 0;
}
- Test Case 1
Input (stdin)
6
gaga
abcde
rotor
xyzxy
abbaab
ababc
Expected Output
YES
NO
YES
YES
NO
NO
- Test Case 2
Input (stdin)
1
gaga
Expected Output
YES
Concatenate code
- Write a C program to concatenate two different strings into single string. How to concatenate two strings into one without using strcat() library function. Adding two strings into one without using inbuilt library function.Concatenation of two strings is the process of joining them together to form a new string. Concatenation basically joins the second string after first string. Concatenation is sometimes also referred as binary addition of strings i.e. + operation.
For example: Codefor + Win = CodeforWin - CODING ARENA
- #include <stdio.h>
#include<string.h>
int main()
{
char s1[100],s2[100];
scanf("%s",s1);
printf("%s",s1);
scanf("%s",s2);
strcat(s1,s2);
printf("\n%s",s2);
printf("\n%s",s1);
return 0;
}
- Test Case 1
Input (stdin)
SRMUniversity
LearningCentre
Expected Output
SRMUniversity
LearningCentre
SRMUniversityLearningCentre
- Test Case 2
Input (stdin)
srmapple
lab
Expected Output
srmapple
lab
srmapplelab
Word Index 1
- Problem Description
Write a C program to find the first occurrence of word in a string using loop
Refer sample Input and Output:
Example 1:
srm university
university
Output 1: university is found at 4
The String university is found at string index 4. Array Index starts from 0
Example 2:
srm university
universit
Output 2:
universit is not found
- CODING ARENA
- #include <stdio.h>
#include <string.h>
#define MAX_SIZE 100
int main()
{
char str[MAX_SIZE];
char word[MAX_SIZE];
int i, j, found;
int strLen, wordLen;
scanf("%[^\n]%*c",str);
scanf("%s",word);
strLen = strlen(str);
wordLen = strlen(word);
for(i=0; i<strLen; i++)
{
found = 1;
for(j=0; j<wordLen; j++)
{
if(str[i + j] != word[j])
{
found = 0;
break;
}
}
if(found == 1)
{
printf("%s is found at %d\n",word,i);
}
}
return 0;
}
- Test Case 1
Input (stdin)
srm apple lab in UB block
apple
Expected Output
apple is found at 4
- Test Case 2
Input (stdin)
srm applelab in UB block
lab
Expected Output
lab is found at 9
String Compare
- Problem Description
Write a program to read to strings and compare them using the function strcmp() and
print a message that the first string is equal, less or greater than the second one.
Example
Input:
SRM
SRMUniversity
Output:
First String is Less Than Second String
Input:
SRMUNIVERSITY
SRMLC
Output:
First String is Greater Than Second String
- CODING ARENA
- #include <stdio.h>
#include<string.h>
int main()
{
char str1[50],str2[50];
scanf("%s%s",str1,str2);
if(strcmp(str1,str2)>0)
{
printf("First String is Greater Than Second String");
}
if(strcmp(str1,str2)<0)
{
printf("First String is Less Than Second String");
}
if(strcmp(str1,str2)==0)
{
printf("Both Strings are Equal");
}
return 0;
}
- Test Case 1
Input (stdin)
SRMUniversity
SRM
Expected Output
First String is Greater Than Second String
- Test Case 2
Input (stdin)
SRM
SRM
Expected Output
Both Strings are Equal
Remove index string 1
- Problem Description
Write a function to remove first occurrence of a word from the string.
- CODING ARENA
- #include <stdio.h>
#include <string.h>
#define MAX_SIZE 100
void removeFirst(char * str, const char * toRemove);
int main()
{
char str[MAX_SIZE];
char toRemove[MAX_SIZE];
scanf("%[^\n]%*c",str);
scanf("%s",toRemove);
removeFirst(str, toRemove);
printf("%s", str);
return 0;
}
void removeFirst(char * str, const char * toRemove)
{
int i, j;
int len, removeLen;
int found = 0;
len = strlen(str);
removeLen = strlen(toRemove);
for(i=0; i<len; i++)
{
found = 1;
for(j=0; j<removeLen; j++)
{
if(str[i+j] != toRemove[j])
{
found = 0;
break;
}
}
if(found == 1)
{
for(j=i; j<=len-removeLen; j++)
{
str[j] = str[j + removeLen];
}
break;
}
}
}
- Test Case 1
Input (stdin)
SRM UNIVERSITY
SRM
Expected Output
UNIVERSITY
- Test Case 2
Input (stdin)
srm university
university
Expected Output
srm
Random order
- Problem Description
Petr, Nikita G. and Nikita are the most influential music critics in Saint-Petersburg. They have recently downloaded their favorite band's new album and going to listen to it. Nikita claims that the songs of entire album should be listened strictly in the same order as they are given, because there is the secret message from the author in the songs' order. Petr, being chaotic, does not think so, hence he loves listening to songs in a random order. Petr is pretty good in convincing other people, so after a two-hours discussion Nikita accepted listening in random order(the discussion's duration was like three times longer than the album's one). In this context random order means following: There are N songs in the album. In the very beginning random song is chosen(here and further "random song" means that every song has equal probability to be chosen). After some song is over the next one is chosen randomly and independently of what have been played before. Nikita G., being the only one who is not going to drop out from the university, wonders, what is the expected number of songs guys have to listen to until every song is played at least once.
- CODING ARENA
- #include <stdio.h>
#include<stdlib.h>
int main()
{
int n,t,i;
double x;
scanf("%d",&t);
while(t–)
{
scanf("%d",&n);
x=1;
for(i=2;i<=n;i++)
x+=(1.0)/i;
printf("%1f\n",n*x);
}
return 0;
}
- Test Case 1
Input (stdin)
3
1
2
3
Expected Output
1.000000
3.000000
5.500000
- Test Case 2
Input (stdin)
5
4
6
3
9
7
Expected Output
8.333333
14.700000
5.500000
25.460714
18.150000
Getting Bits
- Problem Description
Divya ask Devi to write a program to get minimum number of bits to store an integer number. Devi thinks a lot but she could not able to do this.Can you help her to derive a solution for this?
- CODING ARENA::
- #include <stdio.h>
int countbit(int);
int main()
{
int num;
scanf("%d",&num);
printf("%d",countbit(num));
return 0;
}
int countbit(int n)
{
int count=0,i;
if(n==0) return 0;
for(i=0;i<32;i++)
{
if((1<<i)&n)
count=i;
}
return ++count;
}
- Test Case 1
Input (stdin)
127
Expected Output
7
- Test Case 2
Input (stdin)
32767
Expected Output
15
Array Mode
- Problem Description
Write a program to find the mode of the elements in the array.
The mode in a list of numbers refers to the list of numbers that occur most frequently. It is important to note that there can be more than one mode and if no number occurs more than once in the set, then there is no mode for that set of numbers.
Input and Output Format:
Input consists of n+1 integers where n corresponds to the number of elements in the array.
The first integer corresponds to n and the next n integers correspond to the elements in the array.
Refer sample input and output for formatting specifications.
Assume that the maximum number of elements in the array is 20.
Assume that in the input dataset there is 1 mode or no mode at all.
All text in bold corresponds to input and the rest corresponds to output.
- CODING ARENA
- #include <stdio.h>
int main()
{
int a[100],i,j,n,flag=0;
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[j]==a[i])
{
flag=1;
printf("Mode=%d ",a[i]);
}
}
}
if(flag==0)
printf("none");
return 0;
}
- Test Case 1
Input (stdin)
5
2 4 2 3 5
Expected Output
Mode=2
- Test Case 2
Input (stdin)
5
2 4 1 3 5
Expected Output
none
Prime Numbers Between Two Integers
- Problem Description
Program to Display Prime Numbers Between Intervals Using Function
Note:
Include upper and lower limits in the output.
- CODING ARENA
- #include <stdio.h>
int check_prime(int num);
int main()
{
int n1,n2,i,flag;
scanf("%d%d",&n1,&n2);
for(i=n1;i<=n2;i++)
{
flag=check_prime(i);
if(flag==0)
printf("%d\n",i);
}
return 0;
}
int check_prime(int num)
{
int j,flag=0;
for(j=2;j<=num/2;j++)
{
if(num%j==0)
{
flag=1;
break;
}
}
return flag;
}
- Test Case 1
Input (stdin)
13
29
Expected Output
13
17
19
23
29
- Test Case 2
Input (stdin)
3
14
Expected Output
3
5
7
11
13
Sum of 2 Arrays using Functions
- Problem Description
Write a program to find the sum of the corresponding elements in 2 arrays.
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 last n integers correspond to the elements in the second array. Assume that the maximum value of n is 15.
Output Format:
Refer sample output for details
- CODING ARENA
- #include <stdio.h>
int main()
{
int n,a[100],b[100],i;
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=0;i<n;i++)
scanf("%d",&b[i]);
for(i=0;i<n;i++)
printf("%d ",a[i]+b[i]);
return 0;
}
- Test Case 1
Input (stdin)
5
2 3 6 8 2
1 1 1 1 1
Expected Output
3 4 7 9 3
- Test Case 2
Input (stdin)
3
0 9 8
1 2 3
Expected Output
1 11 11
Day and Time
- Problem Description
Define a structure date containing three integers -day,months and year. Write a program using functions to read data, to validate the data entered by the user and then print the date on the screen.
For example,if you enter 31/6/2007 is invalid as June does not has 31 days, similarly if you enter 25/13/2000 then it is invalid month as month ends with 12(1-12. jan to dec). The threshold value for year is 3000 (Invalid Year). Valid year: 0000-2999
Using the structure definition of the above program, write a function to increment that .Make sure that the incremented date is a valid date. Modify the above program to add a specific number of days to the given date.Write a function to compare two date variable.
Output:
33 12 1989 – Invalid Day
31 12 3000 – Invalid Year
31 13 1989 – Invalid Month
25 12 1989- New Date=26 12 1989
Mandatory:
1. Create a Structure as "Date"
2. Create three data members as date(int), month(int), year(int)
3. The structure variable for "Date" structure is "D"
Note: The structure variables, data members and structure name are CASE Sensitive.
Follow the same case mentioned in the mandatory
- CODING ARENA
- #include <stdio.h>
struct Date
{
int date,month,year;
}D;
int main()
{
scanf("%d%d%d",&D.date,&D.month,&D.year);
if(D.year>=0000 && D.year<=2999)
{
if(D.month>=1 && D.month<=12)
{
if((D.date>=1 && D.date<=31) && (D.month==1 || D.month==3 ||D.month==5 || D.month==7 ||D.month==8||D.month==10||D.month==12))
{
printf("\nNew Date=%d %d %d",D.date+1,D.month,D.year);
}
else if((D.date>=1 && D.date<=30) && (D.month==4||D.month==6||D.month==9||D.month==11))
{
printf("\nNew Date=%d %d %d",D.date,D.month,D.year);
}
else if((D.date>=1 && D.date<=28)&& D.month==2)
{
printf("\nNew Date=%d %d %d",D.date,D.month,D.year);
}
else if(D.date==29 && D.month==2 &&(D.year%400==0 ||(D.year%4==0 && D.year%100!=0)))
{
printf("\nNew Date=%d %d %d",D.date,D.month,D.year);
}
else
printf("\nInvalid Day");
}
else
printf("\nInvalid Month");
}
else
printf("\nInvalid Year");
return 0;
}
- Test Case 1
Input (stdin)
31 14 1989
Expected Output
Invalid Month
- Test Case 2
Input (stdin)
25 12 1989
Expected Output
New Date=26 12 1989
Student Management Array of Structure
- Problem Description
1 Create a structure "student".
2. This structure has three members: name (string), roll (integer) and marks (float).
3. Created a structure array of size 3 to store information of 3 students and structure variable as "s".
Hint: s[3];
4. Using for loop, the program takes the information of 3 students from the user and displays it on the screen.
- CODING ARENA
- #include <stdio.h>
struct student
{
char name[10];
int roll;
float marks;
}s[3];
int main()
{
int i;
for(i=0;i<3;i++)
{
s[i].roll=i+1;
scanf("%s",s[i].name);
scanf("%f",&s[i].marks);
}
for(i=0;i<3;i++)
{
printf("Roll number=%d\n",i+1);
printf("Name=%s\n",s[i].name);
printf("Marks=%.2f\n",s[i].marks);
}
return 0;
}
- Test Case 1
Input (stdin)
Bogar 99.33
Siddhar 99.44
Tamil 99.99
Expected Output
Roll number=1
Name=Bogar
Marks=99.33
Roll number=2
Name=Siddhar
Marks=99.44
Roll number=3
Name=Tamil
Marks=99.99
- Test Case 2
Input (stdin)
Tom 98.22
Bob 65.12
Alice 45.43
Expected Output
Roll number=1
Name=Tom
Marks=98.22
Roll number=2
Name=Bob
Marks=65.12
Roll number=3
Name=Alice
Marks=45.43
Nested Structure – Details of Students
- Problem Description
Create two structures as follows:
Structure 1:
Name = student
Data members = name(char), rollno(int)
Structure 2:
Name = dateOfBirth
Data members = date(int), month(int), year(int)
Create Structure Variable as "DOB"
In main function:
1. Create structure variable for student "std"
Hint: struct student std;
2. Input the values of name and roll number
Hint: std.name
3. Input the values of date, month and year
Hint: std.DOB.date
4. Display the name, roll number, Date of Birth.
Note: The structure variables, data members and structure name are CASE Sensitive.
Follow the same case mentioned in the mandatory
- CODING ARENA
- #include<stdio.h>
struct student
{
char name[100];
struct dateOfBirth
{
int rollno,date,month,year;
}DOB;
}std;
int main()
{
scanf("%s%d%d%d%d",std.name,&std.DOB.rollno,&std.DOB.date,&std.DOB.month,&std.DOB.year);
printf("Name=%s\nRollNo=%d\nDate of birth=%d/%d/%d",std.name,std.DOB.rollno,std.DOB.date,std.DOB.month,std.DOB.year);
return 0;
}
- Test Case 1
Input (stdin)
Rajesh
101
25 12 1989
Expected Output
Name=Rajesh
RollNo=101
Date of birth=25/12/1989
- Test Case 2
Input (stdin)
Bogar
102
11 11 1111
Expected Output
Name=Bogar
RollNo=102
Date of birth=11/11/1111
Printing names
- Problem Description
Raja and sakthi plannig to design one echo machine
which replies name whatever name we are saying
as your name is.
Input
Name as Array
Output
your name
- CODING ARENA
- #include <stdio.h>
struct name
{
char ar[10];
}s;
int main()
{
scanf("%s",s.ar);
printf("Hi your name is %s",s.ar);
return 0;
}
- Test Case 1
Input (stdin)
mahesh
Expected Output
Hi your name is mahesh
- Test Case 2
Input (stdin)
ganesh
Expected Output
Hi your name is ganesh
Sum the numbers using union and Structures
- Problem Description
Kamachi decided to write one program in which she has to get one values using structure concept and another values using union concept, the result should add both values.Help to her to write code.
Input Method
Integer ranges from 1 to 999
Output Method
sum of values
- CODING ARENA
- #include <stdio.h>
struct sum
{
int a;
int b;
};
int main()
{
int s1;
struct sum s;
scanf("%d%d",&s.a,&s.b);
s1=s.a+s.b;
printf("%d",s1);
return 0;
}
- Test Case 1
Input (stdin)
3 4
Expected Output
7
- Test Case 2
Input (stdin)
5 6
Expected Output
11
Multiply by 5
- Problem Description
Ram play a game with guna to tell if ram say number gun have to reply
the number multiplied by 5 value, for example if ram say 2 guna has to reply 10.
using structure concept implement it.
Input Method
Integer ranges from 1 to 999
Output Method
Value multiplied by 5
- CODING ARENA
- #include <stdio.h>
struct multiply
{
int a;
}s;
int main()
{
int b;
struct multiply s;
scanf("%d",&s.a);
b=s.a*5;
printf("%d",b);
return 0;
}
- Test Case 1
Input (stdin)
3
Expected Output
15
- Test Case 2
Input (stdin)
4
Expected Output
20
Simple structures
- Problem Description
Write a C program to Store Information and Display it Using Structure
- CODING ARENA
- #include <stdio.h>
int main()
{
struct student
{
char name[80];
int rollno;
float marks;
};
struct student s;
scanf("%s",s.name);
scanf("%d",&s.rollno);
scanf("%f",&s.marks);
printf("Name=%s\n",s.name);
printf("Roll number=%d\n",s.rollno);
printf("Marks=%.1f\n",s.marks);
return 0;
}
- Test Case 1
Input (stdin)
Abi
1001
99.5
Expected Output
Name=Abi
Roll number=1001
Marks=99.5
- Test Case 2
Input (stdin)
Akash
1002
90.3
Expected Output
Name=Akash
Roll number=1002
Marks=90.3
Transformation
- Problem Description
Reverse Polish Notation (RPN) is a mathematical notation where every operator follows all of its operands. For instance, to add three and four, one would write "3 4 +" rather than "3 + 4". If there are multiple operations, the operator is given immediately after its second operand; so the expression written "3 4 + 5" would be written "3 4 5 +" first subtract 4 from 3, then add 5 to that.
Transform the algebraic expression with brackets into RPN form.
You can assume that for the test cases below only single letters will be used, brackets [] will not be used and each expression has only one RPN form (no expressions like a*b*c)
Input
The first line contains t, the number of test cases (less then 100).
Followed by t lines, containing an expression to be translated to RPN form, where the length of the expression is less then 400.
Output
The expressions in RPN form, one per line.
Example
Input:
3
(a+(b*c))
((a+b)*(z+x))
((a+t)*((b+(a+c))^(c+d)))
Output:
abc*+
ab+zx+*
at+bac++cd+^*
- CODING ARENA
- #include <stdio.h>
int main()
{
int cases,top=0,i;
char exp[400],stack[200];
scanf("%d",&cases);
while(cases)
{
scanf("%s",exp);
for(i=0;exp[i];i++)
{
if(exp[i]=='(')
continue;
else if(exp[i]==')')
{
printf("%c",stack[top]);
top–;
}
else if(exp[i]=='+'|| exp[i]=='-'|| exp[i]=='*'|| exp[i]=='/'||exp[i]=='^')
{
top++;
stack[top]=exp[i];
}
else
{
printf("%c",exp[i]);
}
}
cases–;
printf("\n");
}
return 0;
}
- Test Case 1
Input (stdin)
3
(a+(b*c))
((a+b)*(z+y))
((a+t)*((b+(a+c))^(c+d)))
Expected Output
abc*+
ab+zy+*
at+bac++cd+^*
- Test Case 2
Input (stdin)
2
(a+(b*c))
((a+b)*(z+y))
Expected Output
abc*+
ab+zy+*
Time Difference
- Problem Description
Help Rama to achieve his friends task "Time challenge" to display hours minutes and seconds in both 12 and 24 hours format: 24 Hours format : 23:30:12 Standard format : 11:30:12 pm
Refer the sample input and output:
Sample Input 1:
20 25 06
Output 1:
24 Hours Format
20:25:06
12 Hours Format
08:25:06 pm
Sample Input 2:
24 25 06
Output 2:
Invalid Time
Sample Input 3:
23 60 06
Output 3:
Invalid Time
Sample Input 4:
23 56 61
Output 4:
Invalid Time
- CODING ARENA::
- #include <stdio.h>
struct time
{
int h,m,s;
}a;
int main()
{
scanf("%d %d %d",&a.h,&a.m,&a.s);
if(a.h>=24 && a.m>1 &&a.s>2)
{
printf("Invalid Time");
}
else if (a.m>60 || a.s>60)
{
if(a.s>60 || a.m>60)
{
printf("Invalid Time");
}
}
else if (a.h<=12)
{
printf("24 Hours Format");
printf("\n%d:%d:%d",a.h,a.m,a.s);
printf("\n12 Hours Format");
printf("\n%d:%d:%d am",a.h,a.m,a.s);
}
else
{
printf("24 Hours Format");
printf("\n%d:%d:%d",a.h,a.m,a.s);
printf("\n12 Hours Format");
printf("\n%d:%d:%d pm",a.h-12,a.m,a.s);
}
return 0;
}
- Test Case 1
Input (stdin)
23
35
22
Expected Output
24 Hours Format
23:35:22
12 Hours Format
11:35:22 pm
- Test Case 2
Input (stdin)
24
56
59
Expected Output
Invalid Time
Sum of even and odd numbers
- Problem Description
Write a program to find the sum of even and odd numbers in an array.
Input Format:
Input consists of n+1 integers. The first integer corresponds to ?n? , the size of the array. The next ?n? integers correspond to the elements in the array. Assume that the maximum value of n is 15.
Output Format:
Refer sample output for details
- CODING ARENA
- #include <stdio.h>
int main()
{
int n,a[10],i,s=0,s1=0;
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<n;i++)
{
if(a[i]%2==0)
{
s=s+a[i];
}
else
{
s1=s1+a[i];
}
}
printf("even=%d",s);
printf("\nodd=%d",s1);
return 0;
}
- Test Case 1
Input (stdin)
5
2 3 6 8 -1
Expected Output
even=16
odd=2
- Test Case 2
Input (stdin)
7
1 2 3 4 5 6 7
Expected Output
even=12
odd=16
Structures – 1 Students Details
- Problem Description
Create a structure called Student.
struct Student
{
char name[30];
char department[20];
int yearOfStudy;
float cgpa;
};
The structure variable should be "S1"
Write a program to get the details of n students and to display their details, sorted in ascending order based on name.
Input and Output Format:
Refer sample input and output for formatting specification.
Name, Department, Year of study, CGPA.
Students details are sorted based on their "Names" in ascending order
Mandatory :
Note: The structure variables, data members and structure name are CASE Sensitive.
Follow the same case mentioned in the mandatory
- CODING ARENA
- #include <stdio.h>
#include <string.h>
struct Student
{
char name[30];
char department[20];
int yearOfStudy;
float cgpa;
};
int main()
{
struct Student S1[1000];
struct Student t;
int i,j,n;
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%s",S1[i].name);
scanf("%s",S1[i].department);
scanf("%d",&S1[i].yearOfStudy);
scanf("%f",&S1[i].cgpa);
}
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(strcmp(S1[i].name,S1[j].name)>0)
{
t=S1[i];
S1[i]=S1[j];
S1[j]=t;
}
}
}
for(i=0;i<n;i++)
{
printf("Name:%s\n",S1[i].name);
printf("Department:%s\n",S1[i].department);
printf("Year of study:%d\n",S1[i].yearOfStudy);
printf("CGPA:%.1f\n",S1[i].cgpa);
}
return 0;
}
- Test Case 1
Input (stdin)
3
raju cse 1 7.8
somu IT 2 8.2
Jagan swe 3 8.6
Expected Output
Name:Jagan
Department:swe
Year of study:3
CGPA:8.6
Name:raju
Department:cse
Year of study:1
CGPA:7.8
Name:somu
Department:IT
Year of study:2
CGPA:8.2
- Test Case 2
Input (stdin)
2
shujathkhan IT 3 9.1
john cse 3 9.3
Expected Output
Name:john
Department:cse
Year of study:3
CGPA:9.3
Name:shujathkhan
Department:IT
Year of study:3
CGPA:9.1
Lower Triangular Matrix
- Problem Description
A lower triangular matrix is a square matrix in which all the elements above the diagonal are zero.
That is, all the non-zero elements are in the lower triangle:
Write a C program to find whether a given matrix is a lower triangular matrix or not.
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.
Output Format:
Print yes if it is a lower triangular matrix . Print no if it is not a lower triangular matrix.
- CODING ARENA
- #include <stdio.h>
#include<math.h>
int main()
{
int i,j,x,y,flag=0;
scanf("%d%d",&x,&y);
int a[x][y];
for(i=0;i<x;i++)
{
for(j=0;j<y;j++)
{
scanf("%d",&a[i][j]);
}
}
for(i=0;i<x;i++)
{
for(j=i+1;j<y;j++)
{
if(a[i][j]!=0)
{
flag=1;
}
}
}
if(flag==0)
printf("yes");
else
printf("no");
return 0;
}
- Test Case 1
Input (stdin)
3 3
1 0 0
2 1 0
1 1 1
Expected Output
yes
- Test Case 2
Input (stdin)
3 3
1 1 0
2 2 0
1 2 1
Expected Output
no
Front and Back
- Problem Description
Rand has a task to find the sum of first and last digit of number upto given n numbers.Help him in
writing C code to enter any number and find the sum of first and last digit of the number using for loop.
- CODING ARENA
- #include <stdio.h>
int main()
{
int n,fd,ld,sum=0;
scanf("%d",&n);
ld=n%10;
fd=n;
while(n>=10)
{
n=n/10;
}
fd=n;
sum=fd+ld;
printf("%d",sum);
return 0;
}
- Test Case 1
Input (stdin)
1234
Expected Output
5
- Test Case 2
Input (stdin)
8231
Expected Output
9
Printing Next
- Problem Description
Latha and Trisha are friends. They love to play with words. Ishu gives them a task to replace each characters in a string with its next letter. Can you help them to complete this task?
- CODING ARENA
- #include <stdio.h>
#include<string.h>
int main()
{
int a[100],i,l;
char s1[100];
scanf("%s",s1);
l=strlen(s1);
for(i=0;i<l;i++)
{
a[i]=s1[i];
a[i]=a[i]+1;
s1[i]=a[i];
}
printf("%s",s1);
return 0;
}
- Test Case 1
Input (stdin)
abc
Expected Output
bcd
- Test Case 2
Input (stdin)
Appa
Expected Output
Bqqb
Fencing The Ground
- Problem Description
The college ground is rectangular in shape. The Management decides to build a fence around the ground. In order to help the construction workers to build a straight fence, they planned to place a thick rope around the ground. They wanted to buy only the exact length of the rope that is needed. They also wanted to cover the entire ground with a thick carpet during rainy season. They wanted to buy only the exact quantity of carpet that is needed. They requested your help.
Can you please help them by writing a C program to find the exact length of the rope and the exact quantity of carper that is required?
Input Format:
Input consists of 2 integers. The first integer corresponds to the length of the ground and the second integer corresponds to the breadth of the ground.
- CODING ARENA
- #include
int main()
{
int l,b;
scanf("%d%d",&l,&b);
printf("Required length is %dm\n",2*l+2*b);
printf("Required quantity of carpet is %dsqm\n",l*b);
return 0;
}
- Test Case 1
Input (stdin)
50 20
Expected Output
Required length is 140m
Required quantity of carpet is 1000sqm
- Test Case 2
Input (stdin)
121 23
Expected Output
Required length is 288m
Required quantity of carpet is 2783sqm
Alphabets
- Problem Description
Write a program in C to print all the alphabets using pointer
Output:
(Uppercase letters)
- CODING ARENA::
- #include <stdio.h>
int main()
{
char start,end,i;
scanf("%s%s",&start,&end);
for(i=start;i<=end;i++)
printf("%s ",&i);
return 0;
}
- Test Case 1
Input (stdin)
A
J
Expected Output
A B C D E F G H I J
- Test Case 2
Input (stdin)
B
S
Expected Output
B C D E F G H I J K L M N O P Q R S
Pointer – 4
- Problem Description
Write a program to convert floating point values into its integral equivalent using pointer
Input and Output Format:
All float values are displayed correct to 2 decimal places.
All text in bold corresponds to input and the rest corresponds to output.
Note: In the floating point value mantissa is more equal or more than 0.50 then add one to the equivalent integer value
Refer sample input and output for formatting specification
- CODING ARENA
- #include <stdio.h>
#include<math.h>
int main()
{
float a;
scanf("%f",&a);
printf("%.0f",round(a));
return 0;
}
- Test Case 1
Input (stdin)
3.49
Expected Output
3
- Test Case 2
Input (stdin)
3.50
Expected Output
4
Bottle deposits
- Problem Description
In many jurisdictions a small deposit is added to drink containers to encourage people to recycle them. In one particular jurisdiction, drink containers holding one litre or less have a 0.10 deposit, and drink containers holding more than one litre have a
0.25 deposit.
Write a program that reads the number of containers of each size from the user. Your program should continue by computing and displaying the refund that will be received for returning those containers. Format the output so that it includes a rupees
and always displays exactly two decimal places.
- CODING ARENA::
- #include <stdio.h>
int main()
{
int a,b;
float c;
scanf("%d%d",&a,&b);
c=a*0.10+b*0.25;
printf("Refund for Bottles=%.2f",c);
return 0;
}
- Test Case 1
Input (stdin)
23
22
Expected Output
Refund for Bottles=7.80
- Test Case 2
Input (stdin)
157
198
Expected Output
Refund for Bottles=65.20
Biggest of three numbers
- Problem Description
Find the biggest of 3 numbers using pointer
- CODING ARENA
- #include <stdio.h>
#include<math.h>
int main()
{
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
if(a>b)
printf("%d",a);
else if(b>c)
printf("%d",b);
else
printf("%d",c);
return 0;
}
- Test Case 1
Input (stdin)
23 45 10
Expected Output
45
- Test Case 2
Input (stdin)
100 80 10
Expected Output
100
Twos mod
- Problem Description
Bheem has two numbers, he wants to know the modulous value of those two numbers.
Your task is to write a c Program to calculate the modulus of two given numbers.Input the negative numbers and view the output for different test cases
- 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)- 100 93
Expected Output
7
- Test Case 2
Input (stdin)
200 12
Expected Output
8