Switch case in C and print the Day coderinme

Switch case in C

The condition of a Switch case in C is a value.
The case says that if it has the value of whatever is after that case then do whatever follows the colon. The break is used to break out of the case statements.

Break is a keyword that breaks out of the code block, usually surrounded by braces, which it is in. In this case, break prevents the program from falling through and executing the code in all the other case statements. An important thing to note about the switch statement is that the case values may only be constant integral expressions.

The default case is optional, but it is wise to include it as it handles any unexpected cases. It can be useful to put some kind of output to alert you to the code entering the default case if you don’t expect it to.
Switch statements serve as a simple way to write long if statements when the requirements are met.

#include<stdio.h>
void main()
{
	int s;
	printf("Please Enter the number from 1 to 7 for printing the Day of Week --\n");
	scanf("%d",&s);
	switch(s)
	{
	case 1:printf("The Day will be Monday\n");
		break;
		case 2:printf("The Day will be Tuesday\n");
		break;
		case 3:printf("The Day will be Wednesday\n");
		break;
		case 4:printf("The Day will be Thursday\n");
		break;
		case 5 :printf("The Day will be Friday\n");
		break;
		case 6 :printf("The Day will be Saturday\n");
		break;
		case 7 :printf("The Day will be Sunday\n");
		break;
		default:printf("Please Enter the number from 1 to 7 only Try Again\n");
	}
		printf("\nProgram is Compiled and written by CODER in ME\n");	getch();
}

Leave a reply:

Your email address will not be published.