app/site-content/proposals/2009/08/06/c__.c
changeset 8 294ff7ac9cb6
equal deleted inserted replaced
7:3e6916eb3d2c 8:294ff7ac9cb6
       
     1 #include <stdio.h>
       
     2 
       
     3 main()
       
     4 {
       
     5 
       
     6   int n, count = 1;
       
     7   float x, sum = 0,average;
       
     8   do {
       
     9     printf("how many numbers? ");
       
    10     scanf("%d", &n);
       
    11     sum = 0;
       
    12     count = 1;
       
    13     while (count <= n)   {
       
    14       printf("x = ");
       
    15       printf("\n(to end program, enter 0 for x): ");
       
    16       scanf("%f", &x);
       
    17       if (x == 0) 
       
    18         break;
       
    19       sum += x;
       
    20       ++count;
       
    21     }
       
    22     average = sum/n;
       
    23     printf("\nthe average is %f\n", average);
       
    24   } while (x != 0); 
       
    25 }
       
    26 
       
    27