Write a program that uses three arrays ‘roll_no’, ‘name’ and ‘marks’. It inputs roll numbers, names and marks of 10 students into these arrays. It searches the highest marks and displays detail of the student that has highest marks such as its roll number, name, and marks. For example, if roll number is 1 and is stored in roll_no[0], then its name and marks must be stored in name[0] and marks[0] respectively.
So let’s Write Code:
Let’s build logic First:
Algorithm for code:
- Step 1: Start
- Step 2: Declare three arrays one for rollno, second for marks and third for names.
- Step 3: Take inputs from user.
- Step 4: Initialized highest_marks are equal to marks[0].
- Step 5: Compare highest_marks value with marks[i] and store the highest value in highest_marks.
- Step 6: Print Details of the student who has the highest marks.
- Step 7: End Program.
Code:
Write a program that uses three arrays ‘roll_no’, ‘name’, and ‘marks’. It inputs roll numbers, names and marks of 10 students into these arrays. It searches for the highest marks.
#include<iostream>
using namespace std;
main()
{
int roll_no[10], marks[10], i, pos, highest_marks;
char names[10][25];
i = 0;
while(i<=9)
{
cout<<endl<<"Enter record of student : "<<i+1<<endl;
cout<<"Roll number : ";
cin>>roll_no[i];
cout<<"Name : ";
cin>>names[i];
cout<<"Marks : ";
cin>>marks[i];
i++;
}
highest_marks = marks[0];
i = 1;
while(i<=9)
{
if(marks[i] > highest_marks)
{
highest_marks = marks[i];
pos = i;
}
i++;
}
cout<<"\nDetail of student that has highest marks\n";
cout<<"Roll number : "<<roll_no[pos]<<endl;
cout<<"Name : "<<names[pos]<<endl;
cout<<"Marks : "<<marks[pos]<<endl;
}
Hope You will learn Something. Happy Coding.
Visit my YouTube Channel as Well😇 https://www.youtube.com/watch?v=JuIHQ9cLSEw&list=PLbIhkHxfUIItTdcyCb34uRIrPJbXBndIl&index=4
Click on the below Links for more Programming Exercises:
Conditional Structure Exercises: 👉https://myustaadg.com/category/programming-exercises/conditional-structures-exercises/
Array Exercises: 👉https://myustaadg.com/category/programming-exercises/arrays-exercises/