Advertisement
snaptrap013

Untitled

May 28th, 2021
951
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.59 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3.  
  4. void display(float longest,float average,char * name, char * no, char *  team, float attempt[]);
  5. float find_longest(float a[]);
  6. float find_average (float attempt []);
  7.  
  8. int main()
  9. {
  10.     float attempt[5];
  11.     char name[256];
  12.     char no[10];
  13.     char team[100];
  14.     int c;
  15.     float longest, average;
  16.  
  17.     printf("Participant Information");
  18.     printf("\nParticipant name: ");
  19.     gets(name);
  20.     printf("\nParticipant no: ");
  21.     gets(no);
  22.     printf("\nParticipant team: ");
  23.     gets(team);
  24.     printf("Jumping information (in meter):\n");
  25.  
  26.     for (c = 0; c < 5; c++)
  27.     {
  28.         printf ("Attempt %d. =", c+1);
  29.         scanf("%f", &attempt[c]);
  30.     }
  31.  
  32.     longest = find_longest(attempt);
  33.     average = find_average(attempt);
  34.     display(longest, average, name, no, team, attempt);
  35.     return 0;
  36. }
  37.  
  38. float find_longest(float a[]) {
  39.   int c, index = 0;
  40.   float firstarray;
  41.   firstarray = a[0];
  42.   for (c = 0; c < 5; c++)
  43.     if (a[c] > firstarray)
  44.       firstarray = a[c];
  45.   return firstarray;
  46. }
  47.  
  48. float find_average (float attempt [])
  49. {
  50.     float average;
  51.     float total=0;
  52.     for (int k=0; k<5;k++)
  53.     {
  54.         total = total + attempt[k];
  55.     }
  56.     average=total/5;
  57.     return average;
  58. }
  59.  
  60. void display(float longest,float average,char * name, char * no, char *  team, float attempt[])
  61. {
  62.     printf ("\n\nJumping Information\n");
  63.     for (int i=0;i<5;i++)
  64.     {
  65.         printf ("Attempt %d.=%.2f\n",i+1, attempt[i]);
  66.     }
  67.     printf("Longest jump location = %.2f and average value = %.2f.\n", longest, average);
  68. }
  69.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement