Basically, this program consist of different cases for particular number which user will input. Switch case works on input and for this program, the input should be integer since switch(n) where n is already declared as integer. For any other input, the switch case default function will run i.e "Invalid choice". Alsi, the program also consist of break; which is used to come out of the loop of switch case.
Program to print day
#include<stdio.h>#include<conio.h>
void main()
{ int n;
clrscr();
printf("\n program to print day on basis of day no.");
printf("\n\n enter day no. : ");
scanf("%d",&n);
printf("\n\n\t\t");
switch(n)
{ case 1 : printf("monday");break;
case 2 : printf("tuesday");break;
case 3 : printf("wednesday");break;
case 4 : printf("thursday");break;
case 5 : printf("friday");break;
case 6 : printf("saturday");break;
case 7 : printf("sunday");break;
default : printf("invalid choice");break;
}
getch();
}

No comments:
Post a Comment
Guys if you think something is wrong or should be edit than please do comment.