app/site-content/proposals/2009/08/06/c_.c
author Madhusudan.C.S <madhusudancs@gmail.com>
Thu, 06 Aug 2009 20:20:36 +0530
changeset 8 294ff7ac9cb6
permissions -rwxr-xr-x
Added new set of files.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8
294ff7ac9cb6 Added new set of files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     1
#include <stdio.h>
294ff7ac9cb6 Added new set of files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     2
294ff7ac9cb6 Added new set of files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     3
main()
294ff7ac9cb6 Added new set of files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     4
{
294ff7ac9cb6 Added new set of files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     5
294ff7ac9cb6 Added new set of files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     6
  int n, count = 1;
294ff7ac9cb6 Added new set of files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     7
  float x, sum = 0,average;
294ff7ac9cb6 Added new set of files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     8
  do {
294ff7ac9cb6 Added new set of files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     9
    printf("how many numbers? ");
294ff7ac9cb6 Added new set of files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    10
    scanf("%d", &n);
294ff7ac9cb6 Added new set of files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    11
    sum = 0;
294ff7ac9cb6 Added new set of files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    12
    count = 1;
294ff7ac9cb6 Added new set of files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    13
    while (count <= n)   {
294ff7ac9cb6 Added new set of files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    14
      printf("x = ");
294ff7ac9cb6 Added new set of files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    15
      printf("\n(to end program, enter 0 for x): ");
294ff7ac9cb6 Added new set of files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    16
      scanf("%f", &x);
294ff7ac9cb6 Added new set of files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    17
      if (x == 0) 
294ff7ac9cb6 Added new set of files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    18
        break;
294ff7ac9cb6 Added new set of files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    19
      sum += x;
294ff7ac9cb6 Added new set of files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    20
      ++count;
294ff7ac9cb6 Added new set of files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    21
    }
294ff7ac9cb6 Added new set of files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    22
    average = sum/n;
294ff7ac9cb6 Added new set of files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    23
    printf("\nthe average is %f\n", average);
294ff7ac9cb6 Added new set of files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    24
  } while (x != 0); 
294ff7ac9cb6 Added new set of files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    25
}
294ff7ac9cb6 Added new set of files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    26
294ff7ac9cb6 Added new set of files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    27