Question

In: Computer Science

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 up to the user entry (same user entry as above).
Uses a while loop to calculate and display the cube of the number entered (same user entry as above). Uses a while loop to display a multiplication table from one to ten of the number entered (same user entry as above).
Uses a while loop to display the user-entry-number of asterisks (each separated by a tab).
Uses a while loop to prompt the user for 10 additional integer values.
Calculates and displays the sum of the 10 integers entered on the previous step.
Calculates and displays the average of the 10 integers entered on the previous step.

Solutions

Expert Solution

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int i=1,j=11,temp;
    float avg,float_sum;
    int sum,input;
    //First Ten Natural Numbers
    printf("First Ten Natural Numbers:\n");
    while(i<=10)
    {
        printf("%d\t",i);
        i++;
    }
    while(j<=20)
    {
        sum+=j;
        j++;
    }
    //Sum of second set of 10 Natural Numbers
    printf("\nSum of second set of 10 Natural Numbers: %d",sum);
    i=1,sum=0;
    printf("\nEnter a number: ");
    scanf("%d",&input);
    while(i<=input)
    {
        printf("%d\n",i);
        sum+=i;
        i++;
    }
    //Sum of Natural Numbers up to given number (The sum is calculated in the above for loop and printed in following line)
    printf("Sum of Natural Numbers up to %d is: %d\n",input,sum);
    i=0;

    //PRINTING CUBES UPTO GIVEN NUMBER
    printf("\n-----Cubes-----\n");
    while(i<=input)
    {
        printf("\nCube of %d is : %d\n",i,i*i*i);
        i++;
    }
    j=0;
    //MULTIPLICATION TABLE USING WHILE LOOP
    printf("\n-----Multiplication Table-----\n");
    while(j<=10)
    {
        printf("\n%d x j = %d",input,input*j);
        j++;
    }
    i=1;
       printf("\n");
        printf("\n");
    //PRINTING GIVEN NUMBER OF ASTERISKS SEPERATED BY TAB
    while(i<=input)
    {
        printf("*\t");
        i++;
    }
    printf("\n");
    sum=0,i=1;
    //PROMPTING USER FOR 10 INTEGERS
    printf("\nEnter 10 integers: \n");
    while(i<=10)
    {

        scanf("%d",&temp);
        sum+=temp;
        i++;
    }
    //PRINTING SUM OF INTEGERS
    printf("\nSum of 10 integers Entered: %d\n",sum);
    float_sum = sum;
    avg = float_sum/10;
    //PRINTING AVERAGE OF INTEGERS
    printf("\n Average of 10 integers Entered: %.4f\n",avg);
    return 0;
}

Code has comment on each section.The out put has proper messages for each section, hope you find it helpfull

-Thank You


Related Solutions

Write a Java program that uses a while loop to do the following: Repeatedly asks the...
Write a Java program that uses a while loop to do the following: Repeatedly asks the user to enter a number or -1 to exit the program. Keeps track of the smallest and largest numbers entered so far: You will need a variable for the smallest number and another variable for the largest number. Read the first number the user enters, and if it is not -1 set the smallest and largest variables to that number. Use a loop to...
IN C++: Write a program to display the following table. MUST use for-loop Enter the table...
IN C++: Write a program to display the following table. MUST use for-loop Enter the table size: 10 N N^2 Square root of N --------------------------------------------- 1 1 1.00 2 4 1.41 3 9 1.73 ….. 10 100 3.16
Do the following lab by while or Do-while loop. question: Write a c++ program that asks...
Do the following lab by while or Do-while loop. question: Write a c++ program that asks students to enter 3 valid grades and then calculate the average and print it. if the user enters the invalid grade you should print the error message and get the new grade. Hint1: each time your program ask the following question: "Do you want to calculate another average?" and if the answer to this question is "Y" or "y" then you should continue. Hint2:...
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...
Write a program using c++. Write a program that uses a loop to keep asking the...
Write a program using c++. Write a program that uses a loop to keep asking the user for a sentence, and for each sentence tells the user if it is a palindrome or not. The program should keep looping until the user types in END. After that, the program should display a count of how many sentences were typed in and how many palindromes were found. It should then quit. Your program must have (and use) at least four VALUE...
1. Write a Java program from scratch that meets the following requirements: a. The program is...
1. Write a Java program from scratch that meets the following requirements: a. The program is in a file called Duplicates.java that defines a class called Duplicates (upper/lower case matters) b. The program includes a Java method called noDuplicates that takes an array of integers and returns true if all the integers in that array are distinct (i.e., no duplicates). Otherwise it returns false. Make sure the method is public static. example tests: noDuplicates({}) returns true noDuplicates({-1, 1}) returns true...
Write a program that uses a while loop with a priming read to ask the user...
Write a program that uses a while loop with a priming read to ask the user to input a set positive integers. As long as the user enters a number greater than -1, the program should accumulate the total, keep track of the number of numbers being entered and then calculate the average of the set of numbers after the user enters a -1. This is a sentinel controlled-loop. Here is what a sample run should look like: Enter the...
To write a C++ program for following scenario and display requirements: Scenario-based Problem: AIG Insurance wants...
To write a C++ program for following scenario and display requirements: Scenario-based Problem: AIG Insurance wants to create an insurance management system for their clients. The insurance management system will compute the required payments from the clients. The commission of the agent shall also be computed which depends on the amount of insurance type. Insurance Type Amount of Insurance type Agent Commission Life 2500 12.5% of amount Health 1500 10.5% of amount Other inputs 0 0 Computation of monthly payments...
Write a program in C++ coding that utilizes a DO-WHILE loop to redisplay a menu to...
Write a program in C++ coding that utilizes a DO-WHILE loop to redisplay a menu to the user. Ask the user to input their favorite SuperHero and display a positive or funny comment about the chosen SuperHero. If RBG is chosen, display "You can't spell TRUTH without RUTH." Utilize a Do-While Loop to redisplay the menu to the user after item 1, 2 or 3 is executed. If item 4 is chosen, end the program. If the user chooses 4,...
Write a Java program using jGRASP directions are as follows: Uses a while loop to print...
Write a Java program using jGRASP directions are as follows: Uses a while loop to print the numbers from 3 - 19. Uses a do-while loop to print the numbers from 42 - 56. Uses a for loop to print the numbers from 87 - 95. Asks the user for 2 numbers. Uses a loop to print all numbers between the given numbers, inclusive. Note: Consider that your user's second number can be lower! (see example below) Note: Also consider...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT