Declare an array of type int like this. int myArray[ ] = {45,38 ,27, 46, 81, 72, 56, 61, 20, 48, 76, 91, 57, 35,78}; Write all the content of this array to the txt file (name the text file any name). Then close the file. Practically, there will be no output for this exercise. Just two lines for open and close the file. Sample Output: I am writing content of the array to the file. Done writing. Exercise B: Now open this file that you created in exercise four above. Read all the numbers and show these things to the screen: How many numbers you have in the file. Sum of these numbers. Average of these numbers. Sample Output: Now I am reading the data from the file. Total Number of numbers: 15 Sum of all these numbers: 831
C++
Exercise A:
Declare an array of type int like this. int myArray[ ] = {45,38 ,27, 46, 81, 72, 56, 61, 20, 48, 76, 91, 57, 35,78};
Write all the content of this array to the txt file (name the text file any name).
Then close the file.
Practically, there will be no output for this exercise. Just two lines for open and close the file.
Sample Output:
I am writing content of the array to the file.
Done writing.
Exercise B:
Now open this file that you created in exercise four above.
Read all the numbers and show these things to the screen:
How many numbers you have in the file.
Sum of these numbers.
Average of these numbers.
Sample Output:
Now I am reading the data from the file.
Total Number of numbers: 15
Sum of all these numbers: 831
Average = 55.4
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 5 images