Question

In: Computer Science

Question : Write a C program that asks the user to enter an integer between 1...

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;

}

Solutions

Expert Solution

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:


Related Solutions

Write a Java program that asks the user to enter an integer that is used to...
Write a Java program that asks the user to enter an integer that is used to set a limit that will generate the following four patterns of multiples of five using nested loops •Ascending multiples of five with ascending length triangle •Ascending multiples of five with descending length (inverted) triangle •Descending multiples of five with ascending length triangle •Descending multiples of five with descending length (inverted) triangle Use error checking to keep asking the user for a positive number until...
In C#, write a console-based program that asks a user to enter a number between 1...
In C#, write a console-based program that asks a user to enter a number between 1 and 10. Check if the number is between the range and if not ask the user to enter again or quit. Store the values entered in an array. Write two methods. Method1 called displayByVal should have a parameter defined where you pass the value of an array element into the method and display it. Method2 called displayByRef should have a parameter defined where you...
a). Write a program that asks the user to enter an integer N and prints two...
a). Write a program that asks the user to enter an integer N and prints two integers, root and power, such that 1 < power < 6 and N = root ** power. If no such pair of integers exists, it should print a message to that effect. There are two loops, one for power and one for root. Order the loops so that if N = 64, then your program find that N = 8 ** 2 rather than...
Write a C program that asks the user to enter 15 integer numbers and then store them in the array.
Write a C program that asks the user to enter 15 integer numbers and then store them in the array. Then, the program will find the second largest element in array and its index without sorting the array. For example, In this array {-55,-2,1, 2, -3, 0, 5, 9, 13, 1, 4, 3, 2, 1, 0}, the second largest element is 9 [found at index 7].
Question Write a C program that asks the user to enter two integers x and n....
Question Write a C program that asks the user to enter two integers x and n. Then the program computes xn (=x * x * x …… (n times)) using for loop. and give me an output please use printf and scanf #include int main(void) {     //Declare required variables             //read two integers x , n from the keyboard                 //compute xn using for loop                     printf("< Your name >\n");...
Write a C++ program that asks the user to enter the monthly costs for the following...
Write a C++ program that asks the user to enter the monthly costs for the following expenses incurred from operating your automobile: loan payment, insurance, gas, oil, tires, and maintenance. The program should then display the total monthly cost of these expenses, and a projected total annual cost of these expenses. Label each cost. The labels should be left aligned and have a column width of 30 characters. The cost should be aligned right and displayed with two decimal places...
Write a C program that loops and asks a user to enter a an alphanumeric phone...
Write a C program that loops and asks a user to enter a an alphanumeric phone number and converts it to a numeric one. No +1 at the beginning. You can put all code in one quiz1.c file or put all functions except main in phone.c and phone.h and include it in quiz1.c Submit your *.c and .h files or zipped project */ #pragma warning (disable: 4996) //windows #include <stdio.h> #include <string.h> #include <stdbool.h> #include <ctype.h> enum { MaxLine =...
C++ write a program that asks the user to enter the hours and rate then calculate...
C++ write a program that asks the user to enter the hours and rate then calculate the gross pay for an employee, the program should test if the hours are regular (40), any hour more than 40 should be paid with the overtime rate: 1.5*rate. The program should ask repeatedly the user if he/she wants to continue: y or n, if the user types y, then the program should ask for the hours and rate for another employee then display...
write a program in c++ that asks the user to enter their 5 test scores and...
write a program in c++ that asks the user to enter their 5 test scores and calculates the most appropriate mean. Have the results print to a text file and expected results to print to screen.
In the space provided below write a C++ program that asks the user to enter their...
In the space provided below write a C++ program that asks the user to enter their quarterly earnings for the past two years stores the data in a 2-dimensional array. The program then computes both the annual earnings as well as the total earning and prints the results along with the 2-dimensional array on screen as well as onto a file.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT