Teacher has prepared the result of a class containing n number of students. He wants to
give the award to 3 toppers of the class. Display the Result for 3 toppers as reflected as percentage
form in floating type data.
#include <iostream>
using namespace std;
void three_toppers(float marks[], int n)
{
float first, second, third;
for (int i=0;i<n;i++)
{
if (marks[i]>first)
{
third=second;
second=first;
first=marks[i];
}
else if (marks[i]>second)
{
third=second;
second=marks[i];
}
else if (marks[i]>third)
{
third=marks[i];
}
}
cout<<"The results of top three students are: "<<"\n"<<"1. "<<first<<"%"<<"\n"<<"2. "<<second<<"%"<<"\n"<<"3. "<<third<<"%";
}
int main()
{
float student_marks[]={67.0,45.5,98.5,34.0,56.0,87.6,96.5,23.3,17.6,99.0,78.3,35.5};
int num_of_students = sizeof(student_marks)/sizeof(student_marks[0]);
three_toppers(student_marks,num_of_students);
return 0;
}
Comments
Leave a comment