-
Program to read a single digit number and print in words.
#include<stdio.h>
int main(){
int digit;
scanf("%d",&digit);
switch(digit){
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;
default:
printf("Given number is not a single digit number.");
}
return 0;
}
Sample Input1:
9
Sample Output1:
Nine
Sample Input1:
29
Sample Output1:
Given number is not a single digit number.
-
Program to display number of days in a given month.
#include<stdio.h>
int main() {
int month;
scanf("%d",&month);
switch(month){
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
printf("31 days");
break;
case 2:
printf("28 days in Non-Leap Year and 29 days in Leap Year");
break;
case 4:
case 6:
case 9:
case 11:
printf("30 days");
break;
default:
printf("Invalid month");
}
return 0;
}
Sample Input1:
2
Sample Output1:
28 days in Non-Leap Year and 29 days in Leap Year
Sample Input2:
4
Sample Output2:
30 days
-
Program to perform simple calculator operation.
#include<stdio.h>
int main() {
int num1, num2;
char oper;
scanf("%d%c%d",&num1,&oper,&num2);
switch(oper){
case '+':
printf("%d",num1+num2);
break;
case '-':
printf("%d",num1-num2);
break;
case '*':
printf("%d",num1*num2);
break;
case '/':
printf("%d",num1/num2);
break;
case '%':
printf("%d",num1%num2);
break;
default:
printf("Invalid operation");
}
return 0;
}
Sample Input:
4%5
Sample Output:
4