Advertisement
Niloy007

Siam 1

Jun 12th, 2021
712
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.13 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. struct stdInfo {
  4.     int ID;
  5.     char name[40];
  6.     int courseNo;
  7.     int credits[9];
  8.     double grades[9];
  9.     double cgpa;
  10. };
  11.  
  12. int main() {
  13.     int totalStudent;
  14.     printf("Enter the number of students: ");
  15.     scanf("%d", &totalStudent);
  16.     struct stdInfo info[totalStudent];
  17.  
  18.     for (int i = 0; i < totalStudent; i++) {
  19.         printf("\nStudent-%d information:\n", i + 1);
  20.         printf("ID: ");
  21.         scanf("%d", &info[i].ID);
  22.         printf("Name: ");
  23.         getchar();
  24.         gets(info[i].name);
  25.         printf("#course: ");
  26.         scanf("%d", &info[i].courseNo);
  27.         printf("Credits: ");
  28.         for (int j = 0; j < info[i].courseNo; j++) {
  29.             scanf("%d", &info[i].credits[j]);
  30.         }
  31.         printf("Grades: ");
  32.         for (int j = 0; j < info[i].courseNo; j++) {
  33.             scanf("%lf", &info[i].grades[j]);
  34.         }
  35.     }
  36.  
  37.     printf("\nSummary:\n");
  38.     printf("ID\tName\tCGPA\n");
  39.     for (int i = 0; i < totalStudent; i++) {
  40.         printf("%d\t%s\t", info[i].ID, info[i].name);
  41.         double ans = 0, total = 0;
  42.        
  43.         for (int j = 0; j < info[i].courseNo; j++) {
  44.             ans += (info[i].credits[j] * info[i].grades[j]);
  45.             total += info[i].credits[j];
  46.         }
  47.         ans /= total;
  48.         printf("%.4lf\n", ans);
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement