SHARE
TWEET

Untitled

mhdew May 22nd, 2019 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <string.h>
  3. struct StudentInfo
  4. {
  5.     char id[20];
  6.     float cgpa;
  7. };
  8.  
  9. struct StudentInfo students[5];
  10.  
  11. float Student_CGPA(char id[])
  12. {
  13.     int i;
  14.     for(i = 0; i < 5; i++)
  15.     {
  16.         if(strcmp(students[i].id,id)==0)
  17.         {
  18.             return students[i].cgpa;
  19.         }
  20.     }
  21. }
  22. int main()
  23. {
  24. //   struct StudentInfo students[5];
  25.     int i;
  26.     char id[20];
  27.     for(i=0;i<5;i++)
  28.     {
  29.         printf("\nEnter id: ");
  30.         gets(students[i].id);
  31.         fflush(stdin);
  32.  
  33.         printf("\nEnter Cgpa: ");
  34.         scanf("%f",&students[i].cgpa);
  35.         fflush(stdin);
  36.     }
  37.     for(i=0;i<5;i++){
  38.         printf("%s\n%f\n", students[i].id,students[i].cgpa);
  39.     }
  40.     for(i=0;i<5;i++)
  41.     {
  42.         printf("Result: %f\n", Student_CGPA(students[i].id));
  43.     }
  44.  
  45.     return 0;
  46. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top