Berikut Source Code untuk menghitung nilai Maksimal, nilai Minimal dan Rata-rata suatu bilangan yang diinputkan..
#include <stdio.h>
main()
{
int jum, i;
float nilai, min, maks, rata, total = 0;
printf("DATA NILAI MAHASISWA\n");
printf("=========================\n");
printf("Masukkan jumlah data : ");
scanf("%d", &jum);
for(i=1; i<=jum; i++)
{
printf("Masukkan data nilai ke-%d : ", i);
scanf("%f", &nilai);
if(i == 1)
{
min = nilai;
maks = nilai;
}
if (nilai > maks)
maks = nilai;
if (nilai < min)
min = nilai;
total = total + nilai;
}
rata = (total / jum);
printf("========================\n");
printf("Nilai Maks = %g\n", maks);
printf("Nilai Min = %g\n", min);
printf("Rata-rata = %g\n", rata);
}
#include <stdio.h>
main()
{
int jum, i;
float nilai, min, maks, rata, total = 0;
printf("DATA NILAI MAHASISWA\n");
printf("=========================\n");
printf("Masukkan jumlah data : ");
scanf("%d", &jum);
for(i=1; i<=jum; i++)
{
printf("Masukkan data nilai ke-%d : ", i);
scanf("%f", &nilai);
if(i == 1)
{
min = nilai;
maks = nilai;
}
if (nilai > maks)
maks = nilai;
if (nilai < min)
min = nilai;
total = total + nilai;
}
rata = (total / jum);
printf("========================\n");
printf("Nilai Maks = %g\n", maks);
printf("Nilai Min = %g\n", min);
printf("Rata-rata = %g\n", rata);
}
0 komentar:
Posting Komentar