# Write a C++ program that reads N integer numbers from the keyboard, calculates and displays?

- ✓Follow publicly
- ✓Follow privately
- Unfollow

Write a C++ program that reads N integer numbers from the keyboard, calculates and displays the
following information.
1. sum of all positive numbers which are less than 5
2. ...show more

Best Answer

I'll assume you know how to use cin.

For 1) you need a total variable initialized to 0. Every number that is read in use if ((number >0) && (number < 5)) total += number

2) keep a max value initialized to 0 then if (number > maxVal) maxVal = number. After N numbers then you want maxVal % N

3) you need a total variable again (different one) and a count. Increment count everytime number > 2 and add number to the total. After you get all numbers average = total/count

4) factorial is computed by using a loop that goes from 1 to last number and multiplying a running total (intialized to 1) by the current value of the loop index

5) need an array of 3 integers, insert the first 3 numbers into the corresponding element of the array. You can use if statements to compare the values and print the order.

6) A little trickier, this is how you do it.

int lastNumbers[3];

int lastNumIndex = 0;

while getting numbers

lastNumbers[lastNumIndex++] = number;

if (lastNumIndex == 3) lastNumIndex = 0;

end while

You have to keep cycling through the array. Again, at the end use if's to compare the values to get your order to display.

I haven't given you the full program but hopefully this is enough to guide you. Good luck.

For 1) you need a total variable initialized to 0. Every number that is read in use if ((number >0) && (number < 5)) total += number

2) keep a max value initialized to 0 then if (number > maxVal) maxVal = number. After N numbers then you want maxVal % N

3) you need a total variable again (different one) and a count. Increment count everytime number > 2 and add number to the total. After you get all numbers average = total/count

4) factorial is computed by using a loop that goes from 1 to last number and multiplying a running total (intialized to 1) by the current value of the loop index

5) need an array of 3 integers, insert the first 3 numbers into the corresponding element of the array. You can use if statements to compare the values and print the order.

6) A little trickier, this is how you do it.

int lastNumbers[3];

int lastNumIndex = 0;

while getting numbers

lastNumbers[lastNumIndex++] = number;

if (lastNumIndex == 3) lastNumIndex = 0;

end while

You have to keep cycling through the array. Again, at the end use if's to compare the values to get your order to display.

I haven't given you the full program but hopefully this is enough to guide you. Good luck.

Write a C++ program that reads N integer numbers from the keyboard, calculates and displays?

Write a C++ program that reads N integer numbers from the keyboard, calculates and displays the

following information.

1. sum of all positive numbers which are less than 5

2. largest positive number % N

3. average of all positive numbers which are greater than 2

4. factorial of last number

5. last three numbers in ascending order

6. first three numbers in descending order

N should be declared as a constant in your program and it should be equal to the largest digit of your

student id number. Assume N=3, if the largest digit of your student id number is less than 3.

The program should use the formats for inputs and outputs as given in the example below. In this

example it is assumed that N is equal to 4 but in your program N should be equal to the largest digit of

The program should contain only a main function. User defined functions, arrays,classes, linked list etc should not be used

following information.

1. sum of all positive numbers which are less than 5

2. largest positive number % N

3. average of all positive numbers which are greater than 2

4. factorial of last number

5. last three numbers in ascending order

6. first three numbers in descending order

N should be declared as a constant in your program and it should be equal to the largest digit of your

student id number. Assume N=3, if the largest digit of your student id number is less than 3.

The program should use the formats for inputs and outputs as given in the example below. In this

example it is assumed that N is equal to 4 but in your program N should be equal to the largest digit of

The program should contain only a main function. User defined functions, arrays,classes, linked list etc should not be used

Sign in

to add your answer

Discover Questions

- Whats steps would you take if a coworker or classmate is impeding your progress on an assignment?
- Is it necessary for me to learn html before starting with C language?
- At which order should I learn computer programming languages?
- Sup guys ! Is there any good website for science you can learn from? Websites that give extra knowledge. Apart from wikipedia of course :'D?