Question

In: Computer Science

Write a C-program and run it to meet the requirements listed below. Use the nano editor...

Write a C-program and run it to meet the requirements listed below.

Use the nano editor on Windows or Mac or nano/Geany on R-pi or Geany on Mac.

After running the program, it print outs messages on the Terminal and waits for you to accept a

positive number greater than 9. When you enter a positive number greater than 9, it print outs

what you entered to confirm your input. Then, it calculates and prints out the total sum of 1 + 2 +

... + N, where N is what you entered. It repeats three (3) times to test the program.

The lines of your program need to be properly intended. You must include the scanf function.

[Hints: Use printf, scanf, for-loop, and/or while-loop in your program.]

The results on the Terminal should be similar to the following.

X1, X2, and X3 are the random positive numbers you entered on the Terminal, which should be

greater than 9.

Y1, Y2, and Y3 are the total sum that your program calculated. Your program should calculate

the correct total sum.

Do not embed X1, X2, X3, Y1, Y2, and Y3 in your C-program (No hard-coding).

Your program should accept your input (a number greater than 9) in the Terminal and calculate

the total sum three times before returning to the Terminal as shown below.

Let's calculate the total sum.

=> Please enter a positive number greater than 9:

X1

You entered X1.

The total sum is Y1,

=> Please enter a positive number greater than 9:

X2

You entered X2.

The total sum is Y2,

=> Please enter a positive number greater than 9:

X3

You entered X3.

The total sum is Y3,

Three (3) tests have been completed.

Solutions

Expert Solution

C PROGRAM:

#include<stdio.h>
int main()
{
    //variables declaration
    int x,sum;

    printf("Let's calculate the total sum.\n");

    //loop for 3 tests
    for (int i=0;i<3;i++)
    {
        //every time sum equals 0 before calculation
        sum=0;
        printf("=>Please enter a positive number greater than 9\n");
        scanf("%d",&x);

        //checking if number is less than 9
        if(x<=9)
        {
            printf("number is not greater than 9");
            //exit loop
            break;
        }

        printf("You entered %d\n",x);

        // calculation of 1+2+3+..... up to x.
        for(int j=1;j<=x;j++)
            sum=sum +j;

        //printing sum
        printf("The total sum is %d,\n",sum);

        //termination statement
        if(i==2)
            printf("Three (3) tests have been completed");
    }

    return 0;
}

OUTPUT:


Related Solutions

Directions: You are to write a C++ program that meets the instruction requirements below. Deliverables: ·...
Directions: You are to write a C++ program that meets the instruction requirements below. Deliverables: · Your C++ source code file. (The file with the .CPP extension).No other files will be accepted. A screenshot of your program running. Program Instructions: Consider the following incomplete C++ program: #include int main() { … } 1. Write a statement that includes the header files fstream, string, and iomanip in this program. 2. Write statements that declare inFile to be an ifstream variable and...
Program Requirements: Write a C++ program according to the following requirements: 1.   Open the data file...
Program Requirements: Write a C++ program according to the following requirements: 1.   Open the data file Electricity.txt and read each column into an array (8 arrays total). 2.   Also create 2 arrays for the following: Total Fossil Fuel Energy (sum of all fossil fuels) Total Renewable Energy (sum of all renewable sources) Electricity.txt: Net generation United States all sectors monthly https://www.eia.gov/electricity/data/browser/ Source: U.S. Energy Information Administration All values in thousands of megawatthours Year   all fuels   coal       natural gas   nuclear  ...
you can use either vim or nano as text editor Implement the following code in ARM...
you can use either vim or nano as text editor Implement the following code in ARM on Raspberry Pi, compile and run. g=12, h=8, i=2, j=5; f = (g + h) - (i + j); Your program displays the message: f = (g + h) – (i + j) = 13 Note: answer should be calculated not hardcoded
Write any java programming to meet the following requirements. Your project must meet the following requirements:...
Write any java programming to meet the following requirements. Your project must meet the following requirements: 1. Specify input specification      Design input 2. Specify Output Specification     Design Output 3. The class must include set methods and get methods ( with or without parameters both) 4. Must include Array structure 5. Must include Input or Output Files or both 6. Demonstrate your knowledge of an Applet
Linux Scripting Exercises Step 1: Using the nano text editor, enter the code below and save it as welcome.sh, change its permission to executable, run the script, and answer the questions below ( 1.1-1.5):
  Linux Scripting Exercises Step 1: Using the nano text editor, enter the code below and save it as welcome.sh, change its permission to executable, run the script, and answer the questions below ( 1.1-1.5): #!/bin/bash # echo ”Hello $user” echo ”Today is `date` ” echo ”I feel $argv[1]” today echo ”The following users are logged in: `users`” Explain and number your answers for 1.1-1.5 below: 1.1. $user does in line 3 1.2. `date` does in line 4 1.3. $argv[1]...
MATLAB: Write as a script in the editor window of matlab. Quadratic roots. Write a program,...
MATLAB: Write as a script in the editor window of matlab. Quadratic roots. Write a program, quadroots.m, for finding the roots of the second- order polynomial ax2 + bx + c. Use the quadratic equation. The inputs are the coefficients a,b, and c and the outputs are z1 and z2. The program should produce (exactly) the following output in the Command window when run with (a, b, c) = (1, 2, −3):
You are asked to write a simple C++ phonebook application program. Here are the requirements for...
You are asked to write a simple C++ phonebook application program. Here are the requirements for the application. read the contact information from a given input file (phonebook.txt) into a dynamically created array of Contact objects. Each line of the input line includes name and phone information of a contact. Assume that each name has a single part Allow to perform operations on array of data such as search for a person, create a new contact or delete an existing...
Write a C program that meets the following requirements. Uses a while loop to display the...
Write a C program that meets the following requirements. Uses a while loop to display the first 10 natural numbers (on one row, with a tab separating each number) Uses a while loop to find the sum of the second set of 10 natural numbers. Reads a user entry and displays all the natural numbers up to the user entry (on a column list with a new line separating each number). Finds and displays the sum of all natural numbers...
Create a schematic of a circuit using and write C program to run on a PIC...
Create a schematic of a circuit using and write C program to run on a PIC 16F88 that will flash between a red and green LED at 5Hz with the green on 75% of the time and the red on 25% of the time.
C++ DO not use arrays to write this program. Write a program that repeatedly generates three...
C++ DO not use arrays to write this program. Write a program that repeatedly generates three random integers in the range [1, 100] and continues as follows: If the right-most digit of all the three integers is equal, the program displays them in ascending order on the screen and continues. If the generated integers have different right-most digits, they are not displayed and the program continues. The program terminates once the right-most digits of all the three random numbers are...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT