Professional Documents
Culture Documents
Problem Statement:
You are provided with three numbers n1,n2 and n3 and you have to find the
maximum out of these three numbers?
Input Format:
The first line contains three numbers n1,n2 and n3.
Output Format:
Print the maximum number.
Constraints:
1 <=n1,n2,n3 <= 1000
Example
Sample Input
10 20 15
Sample Output
20
Default Code
#include <stdio.h>
int main()
{
return 0;
}
SOLUTION:
#include <stdio.h>
int main()
{
int num1, num2, num3, max;
scanf("%d%d%d", &num1, &num2, &num3);
printf("%d", max);
return 0;
}
Problem Statement:
You are provided with a side of the square and you have to calculate the area and
perimeter of the square.
Input Format:
The first line of the input contains the side of the square.
Output Format:
Print the area and perimeter of the square.
Constraints:
1 <= s <= 1000
Example
Sample Input
50
Sample Output
2500
200
Default Code
#include <stdio.h>
int main()
{
return 0;
}
SOLUTION:
#include <stdio.h>
int main()
{
int side;
scanf("%d%d",&side);
return 0;
}
Problem Statement:
You are provided with a 4-digit number and you have to add 8 to the number and
then divide it by 3. Now, the modulus of that number is taken with 5 and then multiply
the resultant value by 5 and have to print the final result.
Input Format:
The first line of the input contains the four-digit number.
Output Format:
Print the final result.
Constraints:
1000 <= four-digit number <= 10000
Example
Sample Input
2345
Sample Output
20
Default Code
#include <stdio.h>
int main()
{
return 0;
}
SOLUTION:
#include <stdio.h>
int main()
{
int num;
scanf("%d",&num);
return 0;
}
Test case 1 Test case 2 Test case 3 Test case 4
Input Input Input Input
7245 2993 4561 9995
Problem Statement:
You are provided with two numbers and you have to check that if the number is equal,
greater or smaller. If numbers are equal print ”Numbers are equal” else print ”Number 1 is
greater than Number 2”else ”Number 2 is greater than Number 1” .
Input Format:
The first line contains two numbers n1 and n2.
Output Format:
Print the result.
Constraints:
1 <= n1,n2 <= 1000
Example
Sample Input
10 20
Sample Output
Number 2 is greater than Number 1
Default Code
#include <stdio.h>
int main()
{
return 0;
}
SOLUTION:
#include <stdio.h>
int main()
{
int n1,n2;
scanf("%d%d",&n1,&n2);
if(n1==n2){
printf("Numbers are equal");
}
else if(n1>n2){
printf("Number 1 is greater than Number 2");
}
else{
printf("Number 2 is greater than Number 1");
}
return 0;
}
Input Format:
The first line of the input contains a single character ch.
Output Format:
Print the required result accordingly.
Constraints:
A <= ch<= Z
a <= ch<= z
Example
Sample Input
a
Sample Output
Character is an Alphabet
Default Code
#include <stdio.h>
int main()
{
return 0;
}
SOLUTION:
#include <stdio.h>
int main()
{
char ch;
scanf("%c", &ch);
return 0;
}
Problem Statement:
You are provided with three sides of the triangle s1,s2 and s3 and you have to check
whether the triangle is equilateral scalene, or isosceles?
Input Format:
The first line of the input contains three sides of the triangle s1,s2 and s3.
Output Format:
Print an “Equilateral triangle” if the triangle is equilateral and if it's isosceles print
”an Isosceles triangle” else print a ”Scalene triangle” if the triangle is scalene.
Constraints:
1 <= s1,s2,s3 <= 100
Example
Sample Input
444
Sample Output
Equilateral triangle
Default Code
#include <stdio.h>
int main()
{
return 0;
}
SOLUTION:
#include <stdio.h>
int main()
{
int s1,s2,s3;
scanf("%d%d%d", &s1,&s2,&s3);
if((s1==s2) && (s2==s3))
{
printf("\n Equilateral triangle\n");
}
else if((s1==s2) || (s1==s3) || (s2==s3))
{
printf("\n Isosceles triangle\n");
}
else
{
printf("\n Scalene triangle\n");
}
return 0;
}
Problem Statement:
You are provided with two numbers and you have to check to find out the maximum among
two.
Input Format:
The first line contains two numbers n1 and n2.
Output Format:
Print the maximum number.
Constraints:
1 <= n1,n2 <= 1000
Note: Maximum Number always exists.
Example
Sample Input
10 20
Sample Output
20
Default Code
#include <stdio.h>
int main()
{
return 0;
}
SOLUTION:
#include <stdio.h>
int main()
{
int n1,n2;
scanf("%d%d", &n1,&n2);
Input Format:
The first line of the input contains two integers a and b.
Output Format:
Print the required result accordingly.
Constraints:
1 <= a,b<=1000
Example
Sample Input
72 45
Sample Output
3330
Default Code
#include <stdio.h>
int main()
{
return 0;
}
SOLUTION:
#include <stdio.h>
int main()
{
int a,b;
scanf("%d%d", &a,&b);
return 0;
}
Test case Test case Test case Test case
1 2 3 4
Input Input Input Input
322 101 10 98 76 73 12
Question 3: Notes
Problem Statement:
You are provided with a particular amount and you have to print the minimum number of
notes (Rs 500,100,50,20,10,5,2,1) required for the amount.
Input Format:
The first line of the input contains a single integer amount amt.
Output Format:
Print the total number of notes required for the amount.
Constraints:
1 <= amt <= 100
Example
Sample Input
575
Sample Output
500 = 1
100 = 0
50 = 1
20 = 1
10 = 0
5=1
2=0
1=0
Default Code
#include <stdio.h>
int main()
{
return 0;
}
SOLUTION:
#include <stdio.h>
int main()
{
int amount;
int note500, note100, note50, note20, note10, note5, note2, note1;
scanf("%d", &amount);
return 0;
}
Input Format
• The test cases follow Each test case contains of a single line of input, three integers n1,n2, and n3.
•Output Format
For each test case, output in a single line answer, the greatest number.
Sample Input 1:
10 30 -100
Sample Output 1:
30
Solution
#include <stdio.h>
int main()
{
int n1, n2, n3;
scanf("%d %d %d",&n1,&n2,&n3);
return 0;
}
Test Cases
Input 20 30 70 -4 -100 12 20 6
Output
70 0 20
Solution:
#include <stdio.h>
int main() {
int n,x,k;
scanf("%d %d %d",&n,&x,&k);
if(n>=(k/x))
printf("%d \n",k/x);
else
printf("%d\n",n);
return 0;
}
Input:
Take a number N from user
Constraints:
-100<=N<=100
Output:
Print “N is a odd No” or “N is an even No” depending on the input N.
Input Output
STC1 5 5 is an odd No
Solution 16:
#include<stdio.h>
int main()
{
int num;
scanf("%d",&num);
if(num%2==0){
printf("%d is an even No",num);
}else{
printf("%d is an odd No ",num);
}
return 0;
}
Test Cases
Input Output
TC1 53 53 is an
odd No
TC2 34 34 is an
even No
TC3 32 32 is an
even No
Input Format
• The test cases follow Each test case contains of a single line of input, three integers N,X, and K.
•Output Format
For each test case, output in a single line answer, the maximum number of bottles
Aditya can fill completely.
Sample Input 1:
528
Sample Output 1:
4
Sample Input 2:
10 5 4
Sample Output: 2
0
Sample Input 3:
314
Sample Output 3:
3
Explanation:
Test Case 1
The amount of water in the tank is 8 litres. The capacity of each bottle is 2 litres.
Hence, 4 water bottles can be filled completely.
Test Case 2: The amount of water in the tank is 4 litres. The capacity of each
bottle is 5 litres. Hence, no water bottle can be filled completely.
Test Case 3: The amount of water in the tank is 4 litres. The capacity of each
bottle is 1 litre. Aditya has 3 bottles available. He can fill all these bottles
completely using 3 litres of water.
Output
2 1 0
Solution:
#include <stdio.h>
int main() {
int n,x,k;
scanf("%d %d %d",&n,&x,&k);
if(n>=(k/x))
printf("%d \n",k/x);
else
printf("%d\n",n);
return 0;
}
Q16 Write a program to calculate simple interest by taking principle, rate per year and time (in years),
which is given by the user? Print the output in the given format, please don't print any additional text
apart from output.
To calculate the SI for a certain amount of money (P), rate of interest (R) and time (T), the formula is:
SI = (PTR)/100
Here,
SI = Simple interest
P = Principal (sum of money borrowed)
R = Rate of interest p.a
T = Time (in years)
Input :
float input value P,R,T
Output:
float output value of SI
Sample Input 1:
110 10 5
Sample Output 1:
55.00000
Input Output
STC1
34 9 11 33.660000
Solution 16:
#include <stdio.h>
int main()
{
float P , R , T;
scanf("%f %f %f",&P,&R,&T);
float SI = (P * T * R) / 100;
printf("%f\n", SI);
return 0;
}
Constraints: x<=10,000
y<=10,000
Sample Input1:
24
Sample Output1:
Input Output
3
STC1 3 7
6
12
15
18
21
1
STC2 1 7
2
6
7
345
STC3 345 7
690
1035
1380
1725
2070
2415
Solution 17:
#include <stdio.h>
int main()
{
int x,y;
scanf("%d""%d",&x,&y);
for(int i=1; i<=y; i++){
int a = x*i;
printf("%d\n",a);
}
}
SECTION-D (Coding Question)(1x10 mark=10 mark)
Q18Coding Blocks team has 3 bags that they want to take on a vacation. The bags weigh A, B, and C
kgs respectively. They want to check-in exactly two of these bags into the hotel and carry the
remaining one bag with them. The hotel management restrictions says that the total sum of the
weights of the bags that are checked-in cannot exceed D kgs and the weight of the bag which is
carried by the CB Team cannot exceed E kgs. Find if CB team can take all the three bags on the
flight.
Sample Input 1:
1 1 1 15 5
Sample Output 1:
YES
Sample Input 2:
8 7 6 15 5
Sample Output 2:
NO
Sample Input 3:
8 5 7 15 6
Sample Output 3:
YES
Explanation:
Test case 1: CB team can check-in the first and second bag (since 1+1=2≤15) and carry the third bag
with them (since 1≤5).
Test case 2: None of the three bags can be carried in hand without violating the hotel restrictions.
Test case 3: CB team can check-in the first and the third bag (since 8+7≤15) and carry the second
bag with them (since 5≤6).
Input Format •
Each testcase contains a single line of input, five space separated integers A,B,C,D,E.
Output Format
For each testcase, output in a single line answer "YES" if CB team can take all the three bags with
them or "NO" if they cannot. Please note that you have to print YES or NO in uppercase only.
Input Output
3 5 7 10 14
STC1 YES
3 5 17 13 14
STC2 NO
Solution 18:
#include <stdio.h>
int main() {
int a, b, c, d, e;
scanf("%d %d %d %d %d", &a, &b, &c, &d, &e);
printf("YES\n");
printf("YES\n");
printf("YES\n");
else
printf("NO\n");
return 0;
Q11 Magu is a Newspaper vendor. She was unable to calculate her profits day by day. So you create a
C program to calculate her profits with the help of buying price and selling price of the Newspapers.
Read your inputs in form of TP as Total Papers, BP as buying price, SP as selling price in your
program.
Input:
First input giving the total newspapers bought.
Second input corresponds to the buying price of the newspapers.
Output:
Statement with floating point value which is giving the profit in RS.
Input Output
STC1 Rs.150.00
150
3
STC2 Rs.150.00
100
3.50
Solution 11:
#include<stdio.h>
int main()
float tp,bp,sp,profit;
scanf("%f",&tp);
scanf("%f",&bp);
scanf("%f",&sp);
float tsp=tp*sp;
float tbp=tp*bp;
profit=tsp-tbp;
printf("profit =Rs.%.2f",profit);
return 0;}
Test Cases
Input Output
TC1 Rs.150.00
150
3
TC2 Rs.60.00
120
2.50
TC3 Rs.100.00
100
2.50
3.50
TC4 Rs.225.00
150
2.50
TC5 Rs.150.00
100
3.50
Q12 Write a program to check whether a person is eligible for voting or not?
Solution:
#include<stdio.h>
int main()
{
int a ;
printf("Enter the age of the person: ");
scanf("%d",&a);
if (a>=18)
{
printf("Eigibal for voting");
}
else
{
printf("Not eligibal for voting\n");
}
return 0;
}
Test Cases
Test case 1 Test case 2
Input:- Input:-
Enter the age of the person: 19 Enter the age of the person: 17
Output:- Output:-
Sample Input:
u \\ Enter any character.
Sample Output:
u is a Lower case alphabet.
Test Case 1 Test Case 2 Test Case 3 Test Case 4 Test Case 5
Input
u 6 # L c
Output
u is a Lower 6 is a numerical # is a symbol L is a Upper c is a Lower case
case value case alphabet alphabet
alphabet
Solution 12:
#include<stdio.h>
int main()
char a;
scanf("%c",&a);
if((a>=65)&&(a<=90))
else if((a>=97)&&(a<=122))
else if((a>=48)&&(a<=57))
else
{
printf("%c is a symbol",a);
return 0;
Q11 Three friends are residing in a colony. One of their friend newly shifted to their colony, the
fourth friend’s house is equidistance to the other three friend’s houses, which locates like a shape of
triangle. Write a program to determine the point which is equidistance from all the three locations.
Input:
Output:
Location of Fourth friend’s house.
Input Output
STC1 (5.67,9)
(2,4)
(10,15)
(5,8)
STC2 (3.33,4.00)
(2,2)
(3,4)
(5,6)
Solution 11:
#include<stdio.h>
int main()
{
float a1,a2,a3,b1,b2,b3,eqa,eqb;
scanf("%f%f",&a1,&b1);
scanf("%f%f",&a2,&b2);
scanf("%f%f",&a3,&b3);
eqa=(a1+a2+a3)/3;
eqb=(b1+b2+b3)/3;
return 0;
Test Cases
Input Output
TC1 (12.67,5.67)
(4,3)
(33,12)
(1,2)
TC2 (1.33,-3.00)
(-2,-3)
(-1,0)
(7,-6)
TC3 (5.67,9)
(2,4)
(10,15)
(5,8)
TC4 (3.33,4.00)
(2,2)
(3,4)
(5,6)
TC5 (3.00,-2.33)
(5,1)
(-3,-7)
(7,-1)
Test Cases
Test case 1 Test case 2
Input:- Input:-
Enter principal (Amount) :15000 Enter principal (Amount) :10000
Enter rate :2.8 Enter rate :1.5
Enter time (in years) :2 Enter time (in years) :1
Output:- Output:-
Simple Interest is = 840.000000 Simple Interest is = 150.000000
Sample Input:
3 \\ Enter the Month
2004 \\ Enter the Year
Sample Output:
this is a month of 31 days and it is a leap year
Test Case 1 Test Case 2 Test Case 3 Test Case 4 Test Case 5
Input
3 7 2 11 2
Output
this is a this is a month of this is a this is a this is a February
month of 31 30days and it is a February month of 30 month of non-leap
days and it non-leap year month of days and it is year.
is a leap leap year a leap year
year
Solution 13:
#include<stdio.h>
int main()
int month,year;
scanf("%d",&month);
scanf("%d",&year);
switch(month)
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
if((year%4==0)&&((year%400==0)||(year%100!=0)))
else
break;
case 4:
case 6:
case 9:
case 11:
if((year%4==0)&&((year%400==0)||(year%100!=0)))
else
break;
case 2:
if((year%4==0)&&((year%400==0)||(year%100!=0)))
else
{
break;
default:
printf("Invalid month");
return 0;
1. Q11 Get the details of your vehicle’s mileage, petrol available and with that compare you can
cover the distance of your destination?
Input Output
47
156
Solution 11:
#include<stdio.h>
int main()
int mileage,petrol,distance;
scanf("%d",&distance);
scanf("%d",&petrol);
scanf("%d",&mileage);
if(distance<=(petrol*mileage))
printf("can reach");
else{
printf("cannot reach");
return 0;}
Test Cases
Input Output
47
TC2 Cannot reach
17
156
30
250
90
67
Solution :
#include<stdio.h>
void main()
{
int y;
printf("Enter year: ");
scanf("%d", &y);
if( (y%400 == 0) || (y%4 == 0 && y%100 != 0) )
{
printf("%d is a leap year.", y);
}
else
{
printf("%d is not a leap year.", y);
}
}
Test Cases
Test case 1 Test case 2
Output: Output:
Sample Input:
2 \\ Enter the two user inputs.
3 \\ \\
Sample Output:
Add=5.0
Sub=3.0
Mul=6.0
Div=2.0
Test Case 1 Test Case 2 Test Case 3 Test Case 4 Test Case 5
Input
2 3 4 7 3
3 5 6 5 8
Output
Add=5.0 Add=8.0 Add=10.0 Add=12.0 Add=11.0
Solution 12:
#include<stdio.h>
int main()
float a,b,add,sub,mul,div;
scanf("%f",&a);
scanf("%f",&b);
add=a+b;
sub=add-2;
mul=sub*a;
div=mul/b;
printf("add=%.1f\nsub=%.1f\nmul=%.1f\ndiv=%.1f",add,sub,mul,div);
return 0;