Answer to Question #185450 in C++ for RAMAKRISHNA

Question #185450

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.


1
Expert's answer
2021-04-25T18:40:06-0400
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS