snaptrap013 icon

Untitled

snaptrap013 | PRO | 05/28/21 02:19:27 PM UTC | 0 ⭐ | 1099 👁️ | Never ⏰ | []
C |

1.59 KB

|

None

|

0 👍

/

0 👎

#include<stdio.h>
#include<stdlib.h>
 
void display(float longest,float average,char * name, char * no, char *  team, float attempt[]);
float find_longest(float a[]);
float find_average (float attempt []);
 
int main()
{
    float attempt[5];
    char name[256];
    char no[10];
    char team[100];
    int c;
    float longest, average;
 
    printf("Participant Information");
    printf("\nParticipant name: ");
    gets(name);
    printf("\nParticipant no: ");
    gets(no);
    printf("\nParticipant team: ");
    gets(team);
    printf("Jumping information (in meter):\n");
 
    for (c = 0; c < 5; c++)
    {
        printf ("Attempt %d. =", c+1);
        scanf("%f", &attempt[c]);
    }
 
    longest = find_longest(attempt);
    average = find_average(attempt);
    display(longest, average, name, no, team, attempt);
    return 0;
}
 
float find_longest(float a[]) {
  int c, index = 0;
  float firstarray;
  firstarray = a[0];
  for (c = 0; c < 5; c++)
    if (a[c] > firstarray)
      firstarray = a[c];
  return firstarray;
}
 
float find_average (float attempt [])
{
    float average;
    float total=0;
    for (int k=0; k<5;k++)
    {
        total = total + attempt[k];
    }
    average=total/5;
    return average;
}
 
void display(float longest,float average,char * name, char * no, char *  team, float attempt[])
{
    printf ("\n\nJumping Information\n");
    for (int i=0;i<5;i++)
    {
        printf ("Attempt %d.=%.2f\n",i+1, attempt[i]);
    }
    printf("Longest jump location = %.2f and average value = %.2f.\n", longest, average);
}
 

Comments