Answer to Question #335542 in C++ for Sun God Nika

Question #335542

Get a number n from a user. Generate n random numbers and store in the list. Display the list. Compute summation and average of all numbers in the list then display the result on screen.


1
Expert's answer
2022-05-01T19:06:37-0400
#include <iostream>
#include <cstdlib> 
#include <ctime> 
using namespace std;


int main()
{
    int i=0, n, sum = 0;
    float average;
    cout << "Enter the number of random numbers: ";
    cin >> n;
    int arr[n];
    srand(static_cast<unsigned int>(time(nullptr))); 
    
    for(i = 0; i < n; i++){
        arr[i] = (rand() % 10) + 1;
        cout << arr[i] << "\t";
        sum += arr[i];
    }
        
    cout << "\n\nSum: \t\t" << sum << endl;
    cout << "Average: \t" << (float)sum/n << endl;   
    
    return 0; 
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS