Ex: write a C program to print number between 1 to 10 in character formate. How to write a C program to print number between 1 to 10 in character format. C program to print number between 1 to 10 in character format.
Input from user:
Enter the number between 1 to 10: 5
Expected output:
You entered FIVE
Quick links:
1. Accept input (number) from user variable say no.
2. Switch the value of no using switch(no) and match with cases.
3. Inside the body of switch we will give 10 possible values of no i.e. 1 to 10.
4. Therefore we will write 10 cases inside the switch.
5. If any case does not matches then for default case print invalid number.
#include<stdio.h>
void main()
{
int no;
printf("Enter the number between 1 to 10: ");
scanf("%d",&no);
switch(no)
{
case 1:
printf("You entered ONE");
break;
case 2:
printf("You entered TWO");
break;
case 3:
printf("You entered THREE");
break;
case 4:
printf("You entered FOUR");
break;
case 5:
printf("You entered FIVE");
break;
case 6:
printf("You entered SIX");
break;
case 7:
printf("You entered SEVEN");
break;
case 8:
printf("You entered EIGHT");
break;
Input from user:
Enter the number between 1 to 10: 5
Expected output:
You entered FIVE
Quick links:
Step by step logic of the given program:
1. Accept input (number) from user variable say no.
2. Switch the value of no using switch(no) and match with cases.
3. Inside the body of switch we will give 10 possible values of no i.e. 1 to 10.
4. Therefore we will write 10 cases inside the switch.
5. If any case does not matches then for default case print invalid number.
C program to print number between 1 to 10 in character format using switch-case:
#include<stdio.h>
void main()
{
int no;
printf("Enter the number between 1 to 10: ");
scanf("%d",&no);
switch(no)
{
case 1:
printf("You entered ONE");
break;
case 2:
printf("You entered TWO");
break;
case 3:
printf("You entered THREE");
break;
case 4:
printf("You entered FOUR");
break;
case 5:
printf("You entered FIVE");
break;
case 6:
printf("You entered SIX");
break;
case 7:
printf("You entered SEVEN");
break;
case 8:
printf("You entered EIGHT");
break;
case 9:
printf("You entered NINE");
break;
printf("You entered NINE");
break;
No comments:
Post a Comment
If you have any doubts, please discuss here...👇