zoukankan      html  css  js  c++  java
  • bugkExercise 5.5 Calculating average student grades.

    从输出结果来看,这个程序是错的。完全不知道什么意思。

    Exercise 5-5. Write a program that will calculate the average grade for the students in
    each of an arbitrary number of classes. the program should read in all the grades for
    students in all classes before calculating the averages. Output the student grades
    for each class followed by the average for that class.

    //Exercise 5.5 Calculating average student grades.
    #include <stdio.h>
    #include <stdbool.h>
    #include <ctype.h>
    
    int main(void)
    {
      size_t nclasses = 0;                  // Number classes
      size_t nstudents_max = 0;             // Maximum number of students in a class
      char answer = 'N';
    
      printf("How many students are in the largest class? :");
      scanf("%zd", &nstudents_max);
      printf("How many classes are there? :");
      scanf("%zd", &nclasses);
      size_t class = 0;
      size_t student = 0 ;
    
    
      int grades[nclasses][nstudents_max];                     // Stores the grades
      size_t students[nclasses];                               // Stores the number of students in each class
    
      for( class = 0 ; class < nclasses ; ++class)
        {
        printf("Enter the grades for students in class %zd.
    ", class + 1);
        students[class] = 0;                                   // Student count within a class
        while(true)
        {
          printf("Enter the integer grade for student %zd: ", students[class] + 1);
          scanf("%d", &grades[class][students[class]]);
          if(++students[class] == nstudents_max)                // Increment and check student count
          {
            printf("Class %zd complete.", class + 1);
            break;
          }
          printf("Any more students in class %zd (Y or N): ", class + 1);
          scanf(" %c", &answer);
          if(toupper(answer) == 'N')
          break;
        }
      }
      printf("
    ");
      for( class = 0 ; class < nclasses ; ++class)
        {
        int class_total = 0;
        printf("Student grades for class %zd are:
    ", class + 1);
        for( student = 0 ; student < students[class] ; ++student)
        {
          class_total += grades[class][student];
          if((student + 1) % 6 == 0)
            printf("
    ");
          printf("%5d", grades[class][student]);
        }
        printf("
    Average grade for class %zd is %.2lf
    ", class + 1, (double)class_total/students[class]);
      }
        return 0;
    }
  • 相关阅读:
    JDBC
    uml 和 unified process
    关于N9手机第三种交互方式的思考和再设计
    [jQuery插件] jQuery Color Animations颜色动画插件
    Azul发布开源工具jHiccup,为Java提供运行时响应时间分析
    行内元素verticalalign:middle在html5和xhtml1.0及以下版本中的表现差异
    使用maven进行scala项目的构建
    计划FM为人人网提供首个开源Ruby SDK
    Chrome扩展:Run Selected HTML
    Team Foundation Service更新:改善了导航和项目状态速查功能
  • 原文地址:https://www.cnblogs.com/xiaomi5320/p/4190302.html
Copyright © 2011-2022 走看看