C Programming Tutorial

Advertisements

Write program to display the day name of a week in C



       #include<stdio.h>
       #include<conio.h>
       void main()
       {

              int num;
              clrscr();
              
              printf("\nEnter any number b/w 1 to 7 : ");
              scanf("%d",&num);

              if(num == 1)
                     printf("\nMonday");

              else if(num == 2)
                     printf("\nTuesday");

              else if(num == 3)
                     printf("\nWednesday");

              else if(num == 4)
                     printf("\nThursday");

              else if(num == 5)
                     printf("\nFriday");

              else if(num == 6)
                     printf("\nSaturday");

              else if(num == 7)
                     printf("\nSunday");

              else
                     printf("\nInvalid number.");

              getch();
       }
       
   Output : 

              Enter any number b/w 1 to 7 : 5
              Friday




Advertisement