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

Follow
  • 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.
  • Rate
  • Comment
Sign In 

to add your answer

No other Answers

Who is following this question?

    %
    BEST ANSWERS
    Member since:
    Points: Points: Level
    Total answers:
    Points this week:
    Follow
     
    Unfollow
     
    Block
     
    Unblock