okay so im trying to finish this project for school and im having trouble here are the requirements
1.Write a program to generate 100 random numbers (rand() function) and output them to the console.
2.Write a program to generate 100 random numbers and calculate their sum and average. Output the random numbers to the console, ten random numbers on each output line, and then output the sum and average of the numbers.
3.Generate 100 random numbers and calculate their sum and average. Create an array and store the numbers in the array. The sum and average should be the two last values in the array.
4.Generate 100 random numbers and calculate their sum and average. Create an array and store the numbers in the array. The sum and average should be the two last values in the array.
Output the random numbers to the console, ten random numbers on each output line, and then output the sum and average of the numbers.
Sort the random numbers in the array in ascending order (smallest to largest). The sum and average are not part of the sort.
Output the sorted numbers to the console, ten numbers on each line.
5.Generate 100 random numbers and calculate their sum and average. Create an array and store the numbers in the array. The sum and average should be the two last values in the array.
Output the random numbers to the console, ten random numbers on each output line, and then output the sum and average of the numbers. Open a file and send the same output to the file as you sent to the console.
Sort the random numbers in the array in ascending order (smallest to largest). The sum and average are not part of the sort.
Output the sorted numbers to the console, ten numbers on each line. Send the sorted output to the file, as well. It should contain the unsorted numbers, their sum and average, and the sorted numbers.
now i have the first one done but i got really lost after that this is what my code is like for the first part
1 2 3 4 5 6 7 8 9 10 11 12 13
|
#include <stdio.h>
#include <stdlib.h>
int main(void) {
int i;
for (i = 1; i <= 100; i++) {
printf("%d ", 1 + (rand() % RAND_MAX));
if (i % 5 == 0) {
printf("\n");
}
}
return 0;
}
|
but after that i am lost on how to take the output and find their sum and average. im very new to c++ and have only been working with it for about a month so any help or advice would be greatly appreciated.