C Program to Print Day of Week Name

In this tutorial, i am going to show you how to find and print day of week name with the help of if else and switch case statement in c programs.

All C Programs to Print Day of Week Name

  • C Program to Print Day of Week Name using Switch Case
  • C Program to Print Day of Week Name using If Else

C Program to Print Day of Week Name using Switch Case

#include <stdio.h>
int main()
{
  int weekday;
  printf(" Please Enter the Day Number 1 to 7 (Consider 1= Monday, and 7 = Sunday) :  ");
  scanf("%d", &weekday);
  
  switch (weekday)
  {
  	case 1:
  		printf("\n Today is Monday");
		  break;
  	case 2:
  		printf("\n Today is Tuesday");
		  break;
  	case 3:
  		printf("\n Today is Wednesday"); 
		  break;
  	case 4:
  		printf("\n Today is Thursday"); 
		  break;
  	case 5:
  		printf("\n Today is Friday"); 
		  break;
  	case 6:
  		printf("\n Today is Saturday");
		  break;
  	case 7:
  		printf("\n Today is Sunday");
		  break;
	default:
		printf("\n Please enter Valid Number between 1 to 7");
  }
  return 0;
}

The result of the above c program; as follows:

 Please Enter the Day Number 1 to 7 (Consider 1= Monday, and 7 = Sunday) :  25

 Please enter Valid Number between 1 to 7

C Program to Print Day of Week Name using If Else

/* C Program to Print Day Name of Week using Else If Statement */
#include <stdio.h>
int main()
{
  int weekday;
  printf(" Please Enter the Day Number 1 to 7 (Consider 1= Monday, and 7 = Sunday) :  ");
  scanf("%d", &weekday);
  
  if (weekday == 1)
  {
  	printf("\n Today is Monday");  	
  }
  else if ( weekday == 2 )
  {
  	printf("\n Today is Tuesday");  	
  }  
  else if ( weekday == 3 )
  {
  	printf("\n Today is Wednesday");  	
  } 
  else if ( weekday == 4 )
  {
  	printf("\n Today is Thursday");  	
  } 
  else if ( weekday == 5 )
  {
  	printf("\n Today is Friday");  	
  } 
  else if ( weekday == 6 )
  {
  	printf("\n Today is Saturday");  	
  }   
  else if ( weekday == 7 )
  {
  	printf("\n Today is Sunday");  	
  } 
  else
    printf("\n Please enter Valid Number between 1 to 7");
  
  return 0;
}

The result of the above c program; as follows:

 Please Enter the Day Number 1 to 7 (Consider 1= Monday, and 7 = Sunday) :  5

 Today is Friday

Be First to Comment

Leave a Reply

Your email address will not be published.