• Computers & Internet >
  • Programming & Design
  • Computers & Internet >
  • Programming & Design

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.
  • 0
    0
  • Comment
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
Sign in 

to add your answer

Who is following this question?

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