Advertisement
Guest User

Sturcture Average and print maximum Value

a guest
Feb 28th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.84 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<string.h>
  3. #include<conio.h>
  4. struct student{
  5.     char name [50];
  6.     int id ;
  7.     float grade;
  8.  
  9. } ;
  10. int maximum(struct student s[5]) {
  11.      int i,k=0;
  12.      float max=0;
  13.   for (i=0 ;i<5;i++) {
  14.       if(max<s[i].grade)
  15.       { max=s[i].grade;
  16.        k=i;
  17.        }
  18.    
  19.   }
  20.       return k ;
  21.  
  22.  
  23.  
  24. }
  25. float avrage(struct student s[5]) {
  26.    float avg=0,result=0;
  27.    int i= 0 ;
  28.    for(i=0;i<5;i++) {
  29.        avg=avg+s[i].grade; }
  30.    result = avg/5 ;
  31.    return result ;
  32.  
  33. }
  34. int main () {
  35.     int i,result;
  36.     float average;
  37.     struct student s[5] ={
  38.         {"Tamim",111,4.0},{"Rubel",111,3.0},{"Virat",114,3.0},{"Warner",115,2.0},{"Smith",112,3.0} } ;
  39.     result=maximum(s);
  40.     for(i=0;i<5;i++)
  41.     { if (i==result)
  42.     printf("Name %s Id %d Gpa %f\n",s[i].name,s[i].id,s[i].grade); }
  43.     average=avrage(s);
  44.     printf("Average %.2f \n",average);
  45.  
  46.     getch () ;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement