w3resource

C Exercises: Accept day number and display its equivalent day name in the word

C Conditional Statement: Exercise-21 with Solution

Write a C program to read any day number in integer and display the day name in word format.

Visual Presentation:

Accept day number and display its equivalent day name in the word

Sample Solution:

C Code:

#include <stdio.h>  // Include the standard input/output header file.

void main()
{
   int dayno;  // Declare a variable to store the day number.

   printf("Input Day No : ");  // Prompt the user to input the day number.
   scanf("%d",&dayno);  // Read and store the day number.

   switch(dayno)  // Start a switch statement based on the day number.
   {
	case 1:
	       printf("Monday \n");  // Print the corresponding day for day number 1.
	       break;
	case 2:
	       printf("Tuesday \n");  // Print the corresponding day for day number 2.
	       break;
	case 3:
	       printf("Wednesday \n");  // Print the corresponding day for day number 3.
	       break;
	case 4:
	       printf("Thursday \n");  // Print the corresponding day for day number 4.
	       break;
	case 5:
	       printf("Friday \n");  // Print the corresponding day for day number 5.
	       break;
	case 6:
	       printf("Saturday \n");  // Print the corresponding day for day number 6.
	       break;
	case 7:
	       printf("Sunday  \n");  // Print the corresponding day for day number 7.
	       break;
	default:
	       printf("Invalid day number. \nPlease try again ....\n");  // Print a message for invalid day number.
	       break;
      }
}

Sample Output:

Input Day No : 4                                                                                              
Thursday 

Flowchart:

Flowchart: Accept day number and display its equivalent day name in word

C Programming Code Editor:

Previous: Write a program in C to accept a grade and display the equivalent description
Next: Write a program in C to read any digit, display in the word.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/c-programming-exercises/conditional-statement/c-conditional-statement-exercises-21.php