Question

Program C: Start by printing out your name, then your code should prompt the user to...

Program C:

Start by printing out your name, then your code should prompt the user to enter integers using the following prompt:

Enter some integers, end with a 0:

Your code should:

Level 1 Task: count the number of integers entered (not including the 0)

Level 2 Task: produce the sum of all of the integers

Level 3 Task: produce the sum of the even integers

These calculated values need to be displayed as follows: There were ___ numbers read in (not counting the 0). The sum of the numbers is ___. The sum of the even numbers in the collection of numbers is ____. The blanks should be replaced with the values you calculated based on the input. You can assume only integers will be provided as input.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

//note:- if you have any query regarding this then comment below. please upvote

#include<stdio.h>
int main()
{
    int arr[100];
    int i=0;
    int sum=0,even=0;
    printf("Enter some integers, end with a 0: \n");
    while(1)
    {
        int num;
        scanf("%d",&num);
        if(num==0)
            break;
        else
        {
            arr[i]=num;
        }
        i++;
    }
    int j;
    for(j=0;j<i;j++)
    {
        if(arr[j]%2==0)
        {

            even+=arr[j];
        }
        sum+=arr[j];
    }
    printf("There were %d numbers read in (not counting the 0)\n.",i);
    printf("The sum of the numbers is %d\n.",sum);
     printf("The sum of the even numbers in the collection of numbers is %d\n.",even);

}


nter some integers. end with a 0 There were 6 numbers read in not counting the 0 The sum of the numbers is 27 .The sum of the even numbers in the collection of numbers is 12

Add a comment
Know the answer?
Add Answer to:
Program C: Start by printing out your name, then your code should prompt the user to...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C Programming For this task, you will have to write a program that will prompt the...

    C Programming For this task, you will have to write a program that will prompt the user for a number N. Then, you will have to prompt the user for N numbers, and print then print the sum of the numbers. For this task, you have to create and use a function with the following signature: int sum(int* arr, int n); Your code should look something like this (you can start with this as a template: int sum(int* arr, int...

  • 1. Write a program called Numbers that a. prompts the user for a file name. b....

    1. Write a program called Numbers that a. prompts the user for a file name. b. reads that file assuming that its contents consist entirely of integers. c. prints the maximum, minimum, sum, count (number of integers in the file), and average of the numbers. For example, if the file numberinput.dat has the following content: 4 -2 18 15 31 27 Your program should produce the following output: csc% java Numbers Enter file name: numberinput.daft Maximum31 Minimum- -2 Sum -...

  • C++ Program Help Prompt your user to enter a length of a word to search from...

    C++ Program Help Prompt your user to enter a length of a word to search from a string. Use forking to spawn a child process to perform the counting task. Allow the child process to finish and output the number of words found (if any), before prompting the user for the next length. Count all words in the string with this length and output the number of words that correspond to this length. Program keeps asking user for length till...

  • Write a C program code for the scenerio below: An important device carried up to the...

    Write a C program code for the scenerio below: An important device carried up to the International Space Station on the last scheduled flight of space shuttle Endeavor was the Alpha Magnetic Spectrometer (AMS-02). As explained by NASA, the AMS is a particle physics detector, searching for antimatter and dark matter and also measuring cosmic rays. The name strangelets refers to three types of quarks (named u, d or s) which have been discovered experimentally to make up matter, but...

  • write a programming code for the following problem using Visual Basic Studio VB. Write a program that will allow the user to enter series of mumbers and will give some useful statistics about the mam...

    write a programming code for the following problem using Visual Basic Studio VB. Write a program that will allow the user to enter series of mumbers and will give some useful statistics about the mambers Enter Numbers Button Click-Allow the user to enter series of nambers using imput dialog boxes. Use a loop and add the numbers to the listBox as they are input.. Prompt the user to enter"x" to stop addang numbers. Compute Statistics Button Click-Compute the following statistics...

  • Write a program that will loop ten times. In each iteration prompt user to enter an...

    Write a program that will loop ten times. In each iteration prompt user to enter an integer between -50&50. Print the input, keep a running sum of the inputs, and track the minimun and maximum numbers input. After the loop is complete, minimum number entered, maximum number entered, sum of all numberes entered, and average of all numbers entered. Format all output. Before running the loop, print the label "Input values: ". Within the loop, print value entered by user...

  • Change your C++ average temperatures program to: In a non range-based loop Prompt the user for...

    Change your C++ average temperatures program to: In a non range-based loop Prompt the user for 5 temperatures. Store them in an array called temperatures. Use a Range-Based loop to find the average. Print the average to the console using two decimals of precision. Do not use any magic numbers. #include<iostream> using namespace std; void averageTemperature() // function definition starts here {    float avg; // variable declaration    int num,sum=0,count=0; /* 'count' is the int accumulator for number of...

  • Ask uFor Ex. "Prompt user to enter a number" = user enters 10, your program should...

    Ask uFor Ex. "Prompt user to enter a number" = user enters 10, your program should output 1, 2, 3, 4, 5, 6, 7, 8, 9, 10.ser to input a number, and then using a loop control statement (While, For, Do-While), output to the console the numbers beginning from 1, up to and including the number input by the user.

  • the user should be prompted to enter an integer and then your program will produce another...

    the user should be prompted to enter an integer and then your program will produce another integer depending on whether the input was even or odd. The following is an example of what you might see when you run the program; the input you type is shown in green (press Enter at the end of a line), and the output generated by the program is shown in black text. Enter an integer: 1234 Number is even, taking every other digit...

  • Hello, Could you please input validate this code so that the code prints an error message...

    Hello, Could you please input validate this code so that the code prints an error message if the user enters in floating point numbers or characters or ANYTHING but VALID ints? And then could you please post a picture of the output testing it to make sure it works? * Write a method called evenNumbers that accepts a Scanner * reading input from a file with a series of integers, and * report various statistics about the integers to the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT