In this tutorial you will learn about the C Program to find the Day Name of a Week and its application with practical example.
C Program to find the Day Name of a Week
In this tutorial, we will learn to create a C program that will Find the Day Name of a Week using C programming.
Prerequisites
Before starting with this tutorial, we assume that you are the best aware of the following C programming topics:
- Operators in C Programming.
- Basic Input and Output function in C Programming.
- Basic C programming.
- Conditional Statements in C programming.
- Arithmetic operations in C Programming.
Algorithm:-
1 2 3 4 5 6 7 8 9 |
1. Declaring the required variables for the program. 2. Taking the input day from the user. 3. Using the conditional statements to find the name of the day. 4. Printing the Day Name in a week. 5. End the Program. |
Find the Day Name of a Week:-
In today’s program, we will take the input day in a range between 1 to 7 from the user. Then we will pass that variable to the conditional statements to find the name of days. At last, we will print the resulting name of the day to the user.
With the help of the below program, we can find the name of the day in a week.
Program Code:-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
/*C Program to find the Day Name of a Week*/ #include <stdio.h> int main() { //declaring the required variable for the program. int wday; //wday = it will hold the integer input value. //Taking the input number from the user. printf(" Please Enter the Day Number 1 to 7 (Consider 1= Monday, and 7 = Sunday) : "); //Scanning the input form the user. scanf("%d", &wday); if (wday == 1) { //Printing the day of the week printf("\n Today is Monday"); } else if ( wday == 2 ) { //Printing the day of the week printf("\n Today is Tuesday"); } else if ( wday == 3 ) { //Printing the day of the week printf("\n Today is Wednesday"); } else if ( wday == 4 ) { //Printing the day of the week printf("\n Today is Thursday"); } else if ( wday == 5 ) { //Printing the day of the week printf("\n Today is Friday"); } else if ( wday == 6 ) { //Printing the day of the week printf("\n Today is Saturday"); } else if ( wday == 7 ) { //Printing the day of the week printf("\n Today is Sunday"); } else printf("\n Please enter Valid Number between 1 to 7"); return 0; } |
Output:-
In the above program, we have first initialized the required variable.
- wd = it will hold the integer value for the input.
Taking the input day from the user.
Finding the name of the day in a week.
Printing output.