Program in C++ to find weekday based on weekday number
The below program in C++ will find out weekday based on the weekday number input. We will be following the below logic.
1 -> Sunday
2 -> Monday
3 -> Tuesday
4 -> Wednesday
5 -> Thursday
6 -> Friday
7 -> Saturday
Here we are accepting the week day number as input from the user and use switch statement to display the weekday.
Below is the program in C++.
#include<iostream.h> #include #include void main(){ int day; clrscr(); cout << "Enter the day number: "; cin >> day; switch(day){ case 1: cout << "nIts Sunday"; break; case 2: cout << "nIts Monday"; break; case 3: cout << "nIts Tuesday"; break; case 4: cout << "nIts Wednesday"; break; case 5: cout << "nIts Thursday"; break; case 6: cout << "nIts Friday"; break; case 7: cout << "nIts Saturday"; break; default: cout << "nPlease enter number between 1 to 7"; break; } getch(); }
Output
Enter the day number: 5 Its Thursday