Write a program that reads a number between 1 and 7 and displays the name of the corresponding day of the week:

  • "monday" for 1
  • "tuesday" for 2
  • . . .
  • "sunday" for 7

Use the first element of the array to memorize a small error message.


Difficulty level
Video recording
This exercise is mostly suitable for students
#include <stdio.h>
int main()
{
    int N;  
    char DAY[8][10] = {"\aError!", "monday", "tueaday", "wednesday", 
                    "thursday", "friday", "saturday","sunday"};
 
    printf("Enter a number between 1 and 7 : ");
    scanf("%d", &N);

    if (N>0 && N<8)
        printf("The %d%s day of the week is %s.\n",
                                   N, (N==1)?"st":(N==2)?"nd":(N==3)?"rd":"th", DAY[N]);
    else
        puts(DAY[0]);
    return 0;
}

Back to the list of exercises
Looking for a more challenging exercise, try this one !!
Common entries in two binary search trees