Advertisement
Guest User

student_grade

a guest
Nov 27th, 2014
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.90 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<time.h>
  4.  
  5. #define MAX 50
  6.  
  7. struct BasReq{
  8.    int StudID;        // nine digits
  9.    int W[10];         // grade of week i
  10.    float BasR;        // average from W[0] ~ W[9]
  11. };
  12.  
  13.  
  14. int main()
  15. {
  16.     float sum=0;
  17.     srand(time(NULL));
  18.    
  19.     BasReq BR[MAX]={  
  20.      {499410001,{0},0},
  21.      {499410002,{0},0},
  22.      {499410003,{0},0},};
  23.  
  24.     for (int i=0;i<3;i++)
  25.     {
  26.         for (int j=0;j<10;j++)
  27.         {
  28.             BR[i].W[j] = rand()%100;
  29.             sum += BR[i].W[j];
  30.         }
  31.         BR[i].BasR = sum/10;
  32.         sum = 0;
  33.     }
  34.    
  35.     printf("      ID      BasR  W01  W02  W03  W04  W05  W06  W07  W08  W09  W10\n");
  36.     printf("--------------------------------------------------------------------\n");
  37.     for (int i=0;i<3;i++)
  38.     {
  39.         printf("  %d   %2.1f   ", BR[i].StudID, BR[i].BasR);
  40.         for (int j=0;j<10;j++)
  41.         {
  42.             printf("%02d   ", BR[i].W[j]);
  43.         }
  44.         printf("\n");
  45.     }
  46.     system("pause");
  47.     return 1;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement