Exercise 1
a. Declare an array of integers scores with 4 elements.
b. Put in the array with the follows: 20, 15, 12, 47
c. Declare an array of string title with 4 elements.
d. Initialize the array with the follows: “Mid1”, “Mid2”, “Final”, “total”.
e. Print the two table of grads (score and title) using for loop.
The output will as the follows:-
---------------------------
Mid1 20
Mid2 15
Final 12
Total 47
#include <iostream>
using namespace std;
int main ()
{
int scores[] = { 20, 15, 12, 47 };
string strings[] = { "Mid1", "Mid2", "Final", "Total" };
for (int i = 0; i < 4; ++i)
{
cout << strings[i] << " " << scores[i] << "\r\n";
}
return 0;
}
Comments
Leave a comment