Program that will take an integer of length one from the terminal and then display the digit in English.
Sample inputSample output
9 nine
0 zero
#include<stdio.h>
int main(){
int a;
scanf("%d",&a);
if(a>=0&&a<=9){
switch(a){
case 0: printf("Zero"); break;
case 1: printf("One"); break;
case 2: printf("Two"); break;
case 3: printf("Three"); break;
case 4: printf("Four"); break;
case 5: printf("Five"); break;
case 6: printf("Six"); break;
case 7: printf("Seven"); break;
case 8: printf("Eight"); break;
case 9: printf("Nine"); break;
}
}
}
Program that will check whether a triangle is valid or not,
when the three angles (angle value should be such that,
(0 < value < 180) of the triangle are entered through the keyboard.
### [Hint: A triangle is valid if the sum of all the three angles is equal to 180 degrees.]
Sample inputSample output
90 45 45 Yes
30 110 40 Yes
160 20 30 No
0 180 0 No
#include<stdio.h>
int main(){
int a,b,c;
scanf("%d %d %d",&a,&b,&c);
if(a>0&&a<180&&b>0&&b<180&&c>0&&c<180){
((a+b+c)==180)? printf("Yes"):printf("No");
}
else printf("No");
return 0;
}
Program that will take two numbers X & Y as inputs and decide whether X is greater than/less than/equal to Y.
Sample input (X,Y)Sample output
5 -10 5 is greater than -10
5 10 5 is less than 10
5 5 5 is equal to 5
#include<stdio.h>
int main(){
int a,b;
scanf("%d %d",&a,&b);
(a>b)?printf("%d is greater than %d",a,b):(a==b)?printf("%d is equal of %d",a,b):printf("%d is less than %d",a,b);
return 0;
}
Program that will decide whether a year is leap year or not.
### Yes,if(Year%4==0&&year%100!=0)||(Year%400==0)
Sample inputSample output
2000 Yes
2004 Yes
2014 No
#include<stdio.h>
int main(){
int year;
scanf("%d",&year);
((year%4==0 && year%100!=0)||(year%400==0))?printf("Yes"):printf("No");
return 0;
}
Program that will categorize a single character that is entered at the terminal,
whether it is an alphabet, a digit or a special character.
### (Restriction: Without math.h)
Sample inputSample output
z Alphabet
A Alphabet
8 Digit
* Special
#include<stdio.h>
int main(){
char a;
scanf("%c",&a);
(a>='0'&&a<='9')?printf("Digit"):(a>='a'&&a<='z'||a>='A'&&a<='Z')?printf("Alphabet"):printf("Special");
return 0;
}
Program that will evaluate simple expressions of the form-
; where operators are (+, - , *, /)
And if the operator is “/”, then check if nonzero or not.
Sample inputsample output
100 * 55.5 Multiplication: 5550
100 / -5.5 Division: -18.181818
100 / 0 Division: Zero as divisor is not valid!
#include<stdio.h>
int main(){
float number1,number2,result;
char op;
scanf("%f %c %f",&number1,&op,&number2);
if(op=='+'){
result=number1+number2;
printf("addition:%f",result);}
else if(op=='-'){
result=number1-number2;
printf("substraction:%f",result);}
else if(op=='*'){
result=number1*number2;
printf("multiplication:%f",result);}
else if(op=='/'){
if(number2!=0){
result=number1/number2;
printf("division:%f",result);}
else
printf("division: zero as a divisor is not valid!");
}
return 0;
}
Program that will take the final score of a student in a particular subject as input and find his/her grade.
MarksLetter GradeMarksLetter GradeMarksLetter Grade
90-100 A 70-73 C+ Less than 55 F
86-89 A- 66-69 C
82-85 B+ 62-65 C-
78-81 B 58-61 D+
74-77 B- 55-57 D
Sample inputSample output
91.5 Grade: A
50 Grade: F
Program that will construct a menu for performing arithmetic operations.
The user will give two real numbers (a, b) on which the arithmetic
operations will be performed and an integer number (1 <= Choice <= 4)
as a choice. Choice-1, 2, 3, 4 are for performing addition, subtraction,
multiplication, division (quotient) respectively.
Sample input (a, b, Choice)Sample output
5 10
3 Multiplication: 50
-5 10.5
4 Quotient: 0
#include<stdio.h>
int main(){
float a,b;
int i;
scanf("%f %f %d",&a,&b,&i);
switch(i){
case 1:
printf("Addition:%.2f",(a+b)); break;
case 2:
printf("Subtraction:%.2f",(a-b)); break;
case 3:
printf("Multiplication:%.2f",(a*b)); break;
case 4:
printf("Quotient:%.0f",(a/b)); break;
}
return 0;
}
Program that will construct a menu for performing arithmetic operations.
The user will give two real numbers (a, b) on which the arithmetic operations will be performed and
an integer number (1 <= Choice <= 4) as a choice. Choice-1, 2, 3, 4 are for performing addition,
subtraction, multiplication, division respectively.
### If Choice-4 is selected, again the program will ask for another choice
(1 <= Case <=2), where Case-1, 2 evaluate quotient and reminder respectively.
Sample inputSample output
5 10
3 Multiplication: 50
-5 10.5
4
1 Quotient: 0
-5 10.5
4
2 Reminder: -48
#include<stdio.h>
int main(){
float a,b;
int i,j;
scanf("%f %f %d",&a,&b,&i);
switch(i){
case 1:
printf("Addition:%.2f",(a+b)); break;
case 2:
printf("Subtraction:%.2f",(a-b)); break;
case 3:
printf("Multiplication:%.2f",(a*b)); break;
case 4:
scanf("%d",&j);
switch(j){
case 1:
printf("Quotient:%.0f",(a/b)); break;
case 2:
printf("Reminder:%f",(a-(b*(int)(a/b))));break;
}break;
//
}
return 0
}
Program that will construct a menu for performing arithmetic operations.
The user will give two real numbers (a, b) on which the arithmetic operations will be performed and
an integer number (1 <= Choice <= 4) as a choice. Choice-1, 2, 3, 4 are for performing addition,
subtraction, multiplication, division respectively.
If Choice-4 is selected, the program will check if b is nonzero.
If the check is true, the program will ask for another choice (1 <= Case <=2),
where Case-1, 2 evaluate quotient and reminder respectively.
If the check is false, it will print an error message “Error: Divisor is zero” and halt.
Sample inputSample output
5 10
3 Multiplication: 50
-5 10.5
4
2 Reminder: -48
-5 0
4 Error: Divisor is zero
#include<stdio.h>
int main(){
float a,b;
int i,j;
scanf("%f %f %d",&a,&b,&i);
switch(i){
case 1:
printf("Addition:%.2f",(a+b)); break;
case 2:
printf("Subtraction:%.2f",(a-b)); break;
case 3:
printf("Multiplication:%.2f",(a*b)); break;
case 4:
if(b != 0){
scanf("%d",&j);
switch(j){
case 1:
printf("Quotient:%.0f",(a/b)); break;
case 2:
printf("Reminder:%.0f",(((a/b)-(int)(a/b))*100));break;
sol:
printf("Wrong Input");break;
}
}
else printf("Error:Divisor is zero");break;
sol:
printf("Wrong input"); break;
}
return 0;
}
Program for “Guessing Game”:
Player-1 picks a number X and Player-2 has to guess that number within N = 3 tries.
For each wrong guess by Player-2, the program prints “Wrong, N-1 Chance(s) Left!”
If Player-2 successfully guesses the number, the program prints “Right, Player-2 wins!”
and stops allowing further tries (if any left). Otherwise after the completion of N = 3 wrong tries,
the program prints “Player-1 wins!” and halts.
### [ Restriction: Without using loop/break/continue]
### [Hint: Use flag ]
Sample input(X, n1, n2, n3)Sample output
5 12 8 5 Wrong, 2 Chance(s) Left!
Wrong, 1 Chance(s) Left!
Right, Player-2 wins!
100 50 100 Wrong, 2 Chance(s) Left!
Right, Player-2 wins!
20 12 8 5 Wrong, 2 Chance(s) Left!
Wrong, 1 Chance(s) Left!
Wrong, 0 Chance(s) Left!
Player-1 wins!