In: Computer Science
Question :
Write a C program that asks the user to enter an integer between 1 and 7 that represents a weekday number (1 = Sunday, 2 = Monday , …… , 6 = Friday , 7 = Saturday) and it prints the day (i.e., Sunday, Monday, …… , Friday or Saturday). The program continuously asks the user to enter a weekday number till the user responds by ‘N’.
and give me an output please
use printf and scanf
#include <stdio.h> int main(void) { //Declare required variables
//code for reading a weekday number and determining the weekday continuously till the user responds by ‘N’
printf("< Your name >\n"); printf("< Your ID >\n"); return 0; } |
C code:
#include <stdio.h>
int main(void)
{
//initializing number n
char n;
//asking for an integer number
printf("Enter an integer between 1 and 7:
");
//accepting it
scanf(" %c",&n);
//checking if N is entered
while(n!='N'){
//checking if n is
1
if(n=='1')
//printing Sunday
printf("Sunday");
//checking if n is
2
else if(n=='2')
//printing Monday
printf("Monday");
//checking if n is
3
else if(n=='3')
//printing Tuesday
printf("Tuesday");
//checking if n is
4
else if(n=='4')
//printing Wednesday
printf("Wednesday");
//checking if n is
5
else if(n=='5')
//printing Thursday
printf("Thursday");
//checking if n is
6
else if(n=='6')
//printing Friday
printf("Friday");
//checking if n is
7
else if(n=='7')
//printing Saturday
printf("Saturday");
//asking for an integer
number
printf("\nEnter an
integer between 1 and 7: ");
//accepting it
scanf("
%c",&n);
//checking if N is
entered
}
//print Your name
printf("< Your name >\n");
//print Your ID
printf("< Your ID >\n");
return 0;
}
Screenshot:
Input and Output: