This is c program that asks user to print the number on screen. User declares some variables that use to contain the value in it. User also uses the switch statement for this execution. User ask to enter the number and in switch statement user declare for loop i=2 and <20 any number been entered the increment operator will increase i+1. Case 2 has the same condition increment operator will increase the number i+2. And default case will show the message “enter valid number“. Display the result on the screen as output.
Problem Statement:
This is C program that ask user to print the number on screen.
- Declare the variable.
- Using switch statement along with for loop.
- Display the result on screen.
Here is C source code to print the number on screen. Output of this program shown below.
#include<stdio.h>
void main()
{
int a,i;
clrscr();
printf("Enter the Number : ");
scanf("%d",&a);
switch(a)
{
case 2:
for(i=2;i<=20;i++)
{
printf("%d",i);
i=i+1;
printf("\n");
}
break;
case 3:
for(i=3;i<=30;i++)
{
printf("%d",i);
i=i+2;
printf("\n");
}
break;
default:
printf("enter valid number");
}
getch();
}