Kamis, 05 Januari 2012
C++ "array nilai rata-rata max dan min"
#include <iostream.h>
#include <conio.h>
void main()
{
float x[3];
float rata, total=0;
int i;
int maks = -1000; //asumsi nilai paling minimum
int min = 1000; //asumsi nilai paling maksimum
for(i=0;i<3;i++)
{
cout<<"Masukkan nilai["<<i<<"]=";
cin>>x[i];
}
for(i=0;i<3;i++)
{
if(x[i]>maks)
{
maks=x[i];
}
if(x[i]<min)
{
min=x[i];
}
total = total + x[i];
}
cout<<endl;
rata = total /3;
cout<<"Nilai Maksimum :"<<maks<<endl;
cout<<"Nilai Minimum :"<<min<<endl;
cout<<"Nilai Rata - Rata :"<<rata<<endl;
getch();
}
Langganan:
Posting Komentar (Atom)
Tidak ada komentar:
Posting Komentar