In: Computer Science
Consider a 5-by-20 integer array grades:
a) Write a declaration for grades.
b) How many rows does the array have?
c) How many columns does the array have?
d) How many elements does the array have?
e) Write the names of all elements in the first column of the
array.
f) Write the name of the element in the third row and second column
of the array.
g) Write a single statement to assign the value 100 to the element
in the first row and second column.
h) Write a nested loop to get all the elements from the
keyboard.
i) Write a nested for statement to initialize all elements to
zero.
j) Write a statement that copies the values from an array double
mathGrades[20]into the
elements of the first row of grades.
k) Write a series of statements that determine and print the
highest value in the first row of grades.
l) Write a statement to display the elements in column 2 of the
array.
m) Write a statement to calculate the average of the elements in
the first row.
n) Write a series of statements that prints the array grades in a
tabular format. List the
column subscripts as headings across the top and list the row
subscripts at the left of
each row.
If you have any doubts, please ask in the comments, I will try to solve it as soon as possible. If you find my answer helpful, do UPVOTE.Thanks
a) int grades[5][20];
b) array has 5 rows
c) array has 20 columns
d) array has 5*20=100 elements
e) Name of Elements of first columns : grades[0][0], grades[1][0], grades[2][0], grades[3][0], grades[4][0]
f) Name of element of third row and second column - grades[2][1]
g) grades[0][1]=100;
h)
for(int i=0;i<5;i++)
for(int j=0;j<20;j++) cin>>grades[i][j];
i)
for(int i=0;i<5;i++)
for(int j=0;j<20;j++) grades[i][j]=0;
j)
for(int i=0;i<20;i++) grades[0][i]=mathGrades[i];
k)
int max=grades[0][0];
for(int i=1;i<20;i++) if(grades[0][i]>max) max=grades[0][i];
cout<<max;
l)
for(int i=0;i<5;i++) cout<<grades[i][1]<<endl;
m)
int sum=0;
for(int i=0;i<20;i++) sum=sum+grades[0][i];
cout<<sum/20;
n)
cout<<" ";
for(int i=0;i<20;i++) cout<<i;
for(int i=0;i<5;i++)
{
cout<<i;
for(int j=0;j<20;j++)
cout<<grades[i][j];
cout<<endl;
}