Q:-C program to enter week number and print day name of week
This C program will ask the user to enter any number between 1 to 7, where 1 is Monday, 2 is Tuesday, 3 = Wednesday, 4 = Thursday, 5 = Friday, 6 = Saturday, and 7 = Sunday. Based on the user entered integer value this program will print the day name.
#include<stdio.h> #include<conio.h> void main() { int week; clrscr(); printf("Enter week number (1-7): "); scanf("%d", &week); if(week == 1) { printf("Monday"); } else if(week == 2) { printf("Tuesday"); } else if(week == 3) { printf("Wednesday"); } else if(week == 4) { printf("Thursday"); } else if(week == 5) { printf("Friday"); } else if(week == 6) { printf("Saturday"); } else if(week == 7) { printf("Sunday"); } else { printf("Invalid Input! Please enter week number between 1-7."); } getch(); }
#include<stdio.h> #include<conio.h> void main() { int week; clrscr(); printf("Enter week number (1-7): "); scanf("%d", &week); switch (week) { 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("\n Please enter Valid Number between 1 to 7"); } }