9. Program that uses a two dimensional array to initialize the scores of students, arranged in five rows with five students in each row. The program inputs the row number and student number in that row and then displays the scores of the student.
Chapter 7:
Arrays
Programming Exercise
Problem # 9:
Write a program that uses a two dimensional array to initialize the scores of students. The students are arranged in five rows with five students in each row. The program inputs the row number and student number in that row and then displays the scores of the student.
Solution:
#include<iostream>
#include<conio.h>
using namespace std;
int main ()
{
int scores[5][5], i, j, k, l;
for(i=0;i<5;i++)
{
cout<<"Enter scores for the student "<<i+1<<endl;
for(j=0;j<5;j++)
{
cin>>scores[i][j];
}
}
cout<<"Enter row number:";
cin>>k;
cout<<"Enter student number in that row:";
cin>>l;
if(k<=5&&l<=5)
cout<<"Score is "<<scores[k][l];
else
cout<<"Invalid input.";
}
#include<conio.h>
using namespace std;
int main ()
{
int scores[5][5], i, j, k, l;
for(i=0;i<5;i++)
{
cout<<"Enter scores for the student "<<i+1<<endl;
for(j=0;j<5;j++)
{
cin>>scores[i][j];
}
}
cout<<"Enter row number:";
cin>>k;
cout<<"Enter student number in that row:";
cin>>l;
if(k<=5&&l<=5)
cout<<"Score is "<<scores[k][l];
else
cout<<"Invalid input.";
}
Output:
Let me know in the comment section if you have any question.
Previous Post:
8. Program that inputs ten floating point numbers in an array. It displays the values which are greater than the average value of the array.
Comments
Post a Comment