Home
C Programming Language
_Tutorials
_Programs
Python Programming
Data Analytics
About Us
Contact Us
Privacy Policy
MyShop24
Geeky Session
Home
C Program
program to print day of week using switch statement
program to print day of week using switch statement
Geeky Session
Hello friends, in this example, you will learn how to
print day of week using switch statement
in C programming language using following topics:
Data Types
Variables And Constants
Conditions Statements
Loops
#include
int main() { int day; printf("Enter Number of day: \n"); scanf("%d", &day); switch(day) { 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 Input.\n"); } return 0; }
Output:
Enter Number of day: 5
Friday
Explaination Of Program:
Input day number from user, Store it in variable 'day'
Switch the value of 'day', use switch(day).
There can be 7 possible attempt of day, from 1 to 7. Therefore write 7 case inside switch. In addition, add default case as an else block.
For case 1: print "MONDAY",
For case 2: print "TUESDAY" and so on.
Print "SUNDAY" for case 7.
If any case does not matches then, for default: case print "Invalid Input".
Post a Comment
0 Comments
Tutorials Series
Basic Of Computer
C Program
C Programming
Python Programming Language
Get a .NET @₹399/Yr
Contact Form
Name
Email
*
Message
*
Search Artical
Check Your Website
Translate
POPULAR POSTS
Paragraph In HTML
What Is Computer Programing Language And Classification Of Programming Language
Headings In HTML
Social Plugin
Popular Posts
Learn C Programming Language |
10/25/2019 02:25:00 pm
Functions in C Programming Language
12/03/2019 12:32:00 pm
What Is Computer Programing Language And Classification Of Programming Language
10/23/2019 07:43:00 pm
0 Comments