You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
1. Write a program that takes 5 students marks as input and displays it in ascending order.
#include<iostream>usingnamespacestd;classstudentMarks {
public:int i, j, temp;
int arr[5];
voidgetInput() {
for (i = 0; i < 5; i++){
cout << "Enter marks of " << i+1 << " student: ";
cin >> arr[i];
}
}
voidsortArray() {
for (i = 0; i < 5; i++){
for (j = i; j < 5; j++){
if (arr[i] > arr[j+1]){
temp = arr[i];
arr[i] = arr[j+1];
arr[j+1] = temp;
}
}
}
}
voidshowOutput() {
cout << "Marks in the ascending order are: " << endl;
for (i = 0; i < 5; i++){
cout << arr[i] << "";
}
}
};
intmain(){
studentMarks stu;
stu.getInput();
stu.sortArray();
stu.showOutput();
return0;
}
Output
> Enter marks of 1 student: 4> Enter marks of 2 student: 8> Enter marks of 3 student: 9> Enter marks of 4 student: 6> Enter marks of 5 student: 4> Marks in the ascending order are:> 4 4 6 8 9