Saturday, May 21, 2011

Program C Menghitung Rata-Rata

#include <stdio.h>
#include <conio.h>

float nilai[1000];
int n, i, sum;
float rerata;

main ()
{
     printf("Jumlah : ");
     scanf("%d", &n);

     sum=0;
     for(i=0; i<=n-1; i++)
     {
              printf("Data ke %d: ", i+1);
              scanf("%f", &nilai[i]);
              sum+=nilai[i];
     }
     rerata = sum / n;

     printf("Rerata: %.3f", rerata);
     printf("\n\n====================================================\n");
     printf("\t\tVera Suryaningsih\n\tCopyright spirit221.blogspot.com\n");
     printf("\n====================================================\n");
     getch();
     return 0;       
}

Output

0 comments:

Post a Comment