Computer Science, asked by palak101318, 4 months ago

Write a program to print the Days of week using ELSEIF with ENDIF statement

Answers

Answered by dakshkumar13
6

Answer:

please mark me as brain list

In this program, we will take a number between 1 to 7 as input from user, where 1 corresponds to Monday, 2 corresponds to Tuesday and so on. We will use if else ladder statement to print name of day in words.

Answered by Anonymous
1

Explanation:

program to print days of week in words

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

/*

* C program to print day of week name

*/

#include <stdio.h>

int main() {

int day;

/*

* Take the Day number as input form user

*/

printf("Enter Day Number (1 = Monday ..... 7 = Sunday)\n");

scanf("%d", &day);

/* Input Validation */

if(day < 1 || day > 7){

printf("Invalid Input !!!!\n");

return 0;

}

if(day == 1) {

printf("Monday\n");

} else if(day == 2) {

printf("Tuesday\n");

} else if (day == 3) {

printf("Wednesday\n");

} else if(day == 4) {

printf("Thursday\n");

} else if(day == 5) {

printf("Friday\n");

} else if(day == 6) {

printf("Saturday\n");

} else {

printf("Sunday\n");

}

return 0;

}

Output

Enter Day Number (1 = Monday ..... 7 = Sunday)

4

Thursday

Enter Day Number (1 = Monday ..... 7 = Sunday)

7

Sunday

Enter Day Number (1 = Monday ..... 7 = Sunday)

12

Invalid Input !!!!

Similar questions