Advertisement
rafikamal

Student Record

Jan 27th, 2013
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.77 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. #define SIZE 20
  4. #define MAX 100
  5.  
  6. struct studentInfo
  7. {
  8.     char name[SIZE];
  9.     int n;
  10. };
  11.  
  12. int main()
  13. {
  14.     struct studentInfo s[MAX];
  15.     int n, i, max, maxPosition;
  16.    
  17.     printf("How many students? ");
  18.     scanf("%d", &n);
  19.     getchar();
  20.    
  21.     for(i = 0; i < n; i++)
  22.     {
  23.         printf("Enter the name of stduent %d: ", i+1);
  24.         gets(s[i].name);
  25.         printf("Enter the number of student %d: ", i+1);
  26.         scanf("%d", &s[i].n);
  27.         getchar();
  28.     }
  29.    
  30.     max = s[0].n;
  31.     maxPosition = 0;
  32.    
  33.     for(i = 1; i < n; i++)
  34.     {
  35.         if(s[i].n > max)
  36.         {
  37.             max = s[i].n;
  38.             maxPosition = i;
  39.         }
  40.     }
  41.    
  42.     printf("Maximum number obtained is %d by %s\n", max, s[maxPosition].name);
  43.    
  44.     return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement