exercise 4(unit 3) solution

Written by Unknown on Thursday 30 August 2012 at 12:54

Dear asahi,

Here is how to solve exercise 4.

The QUESTION IS:


So.. 
To solve it..
1.  You must understand what the programming will do?
2.  Write down the flow of the programming or you might straight away draw the flow chart.

the example on the flow chart is as followed:



STEP 2:

base on the flow chart.
write a coding.
Here is the example which implementing while loop.


#include <stdio.h>


main()
{
    int a =1;
    float total = 0;
    int total_A = 0;
    int total_B = 0;
    int total_C = 0;
    int total_D = 0;
    int total_F = 0;
    float marks;

    while (a<19)  // be aware that in the flow chart i just use 11 for 10 value, in the test data it give 18    
                           values.
    {
        printf("\nInsert the %d's student's marks = ", a);
        scanf("%f", &marks);

        if (marks>100) {
          printf("Invalid marks value(must be less than 100)");
     } else if (marks>=90) {
          //printf("Grade is: A");
          total_A+=1;
        } else if (marks>=70) {
            //printf("Grade is: B");
            total_B+=1;
          } else if (marks>=50) {
              //printf("Grade is: C");
              total_C+=1;
            } else if (marks>=35) {
                //printf("Grade is: D");
                total_D+=1;
              } else if (marks>=0) {
                  //printf("Grade is: F");
                  total_F+=1;

                } else {
                  printf("Invalid score");
                }

               a++;
    }

    printf("A's scorer = %d\n",total_A);
    printf("B's scorer = %d\n",total_B);
    printf("C's scorer= %d\n",total_C);
    printf("D's scorer= %d\n",total_D);
    printf("D's scorer= %d\n",total_F)

   }



0 Responses to "exercise 4(unit 3) solution"

Pages

Total Pageviews

Powered by Blogger.

About the author

This blogs is developed by Norhamimi Hamdan. She works as a lecturer for Embedded System Department at Kolej kemahiran Tinggi MARA Beranang. The main purpose of this blogs is to provide information/refferences sources for students of wireless embedded devices and c programming courses.