Computer Science, asked by bharathsiva108, 5 months ago

Prog
1
2
A marathon is a long-distance race with an official distance of
42.195 kilometres (26 miles 385 yards), usually run as a road race
or footrace.
A local marathon was organized at Bavdhan, Pune. The distance
actually covered by the participants has been recorded in an
array Rſ which is an integer array holding the values in
kilometres. If there are N number of participants who started
running at a particular time, then the size of Ris N. The
participants should cover a distance more than 0.0 km to get
recorded in array RI.
Find the maximum distances covered by 3 highest racers
excluding finishers. If there are only one or two racers excluding
finishers, give their distances covered.
RO will be Input float array, Write a code to take Input array RO.
and return 3 maximum distances excluding Finishing Distance d,
d = 42.195 km.
Example 1:
Input Values
Enter the distances covered by athlets in Marathon (Kilometers)
please
Ipress q to terminate):
42.195
42.195
42.195
Compile​

Answers

Answered by vansh383344
4

Answer:

please make me a brainliest

Answered by pruthaasl
0

Answer:

#include <iostream>

using namespace std;

#define MAX 100

int main() {

   float RO[MAX];

   float max[3];

   int n,i,j,k;

   float t;

   cout<<"\nEnter number of participants: ";

   cin>>n;

   cout<<"\nEnter the distances covered by athletes in marathon(kilometers). Please press q to terminate: ";

   for(i=0;i<n;i++)

       cin>>RO[i];

   for(i=0;i<n;i++)

       {

           for(j=0;j<n;j++)

           {

               if(RO[i]>RO[j])

               {

                   t=RO[i];

                   RO[i]=RO[j];

                   RO[j]=t;

               }

           }

       }

   cout<<"\nThe three maximum distances excluding the finishing distance are: ";

   k=0;

   for(i=0;i<n;i++)

       {

       if(RO[i]!=42.195)

       max[k]=RO[i];

       k++;

       if(k<3)

       continue;

       }

   for(k=0;k<3;k++)

   {

   cout<<max[k]<<" ";

   }

   return 0;

}

Explanation:

  1. We first declare the necessary variables and an array to store the distances.
  2. Take the number of participants from the user and set it as the array length.
  3. Next step is to take the distances covered as inputs from the user and store them in the declared array.
  4. Then we sort the distances in descending order to find the maximum distances other than the finishing distance.
  5. Once the data is sorted, we then each array element whether it is equal to 42.195 or not.
  6. If the result is true, then that array element is skipped and the next element is checked.
  7. If the result is false, it implies that this distance is the greatest other than the finishing distance. So, the value is printed as the maximum distance.
  8. The counter to keep a track of the three maximum distances is incremented.
  9. Steps 5 to 8 are repeated until the counter value becomes equal to three, i.e., giving the three maximum distances.
  10. The values of the three maximum distances are printed and the program is terminated.

#SPJ3

Similar questions