Program Array Hitung Genap, Ganjil, Maximum, Minimum, Median, Rata |
/*filename = Program Array Hitung Genap, Ganjil, Median, Rata */
/*Oleh : fk_seven */
/*Date : 14 Agustus 2011 */
#include <iostream.h>
#include <conio.h>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
main()
{
//Deklarasi variabel dan Konstanta
atas :
clrscr();
char lagi;
int a, x[10], n, i, genap, ganjil, lama;
float total=0, me, rata, maks, min;
//Proses input
cout<<"\t\t-----------------------------------------------------"<<endl;
cout<<"\t\t Program Array Hitung Genap, Ganjil, Median & Rata "<<endl;
cout<<"\t\t-----------------------------------------------------"<<endl<<endl;
cout<<"\t\tJumlah Dari Data : "; cin>>n;
cout<<endl;
for(i=0;i<n;i++)
{
cout<<"\t\tInput Nilai Data Ke-"<<i+1;
cout<<endl;
cout<<"\t\tNilai Data = "; cin>>x[i];
total=total+x[i];
}
rata=total/n;
for(i=0;i<n;i++){
if(x[i]%2==0)
cout<<"\t\tGenap = "<<x[i]<<endl;
else
continue;}
for(i=0;i<n;i++){
if(x[i]%2==1)
cout<<"\t\tGanjil = "<<x[i]<<endl;
else
continue;}
maks=x[1];
for(i=0;i<n;i++){
if(x[i]>=maks){
maks=x[i];}
else
continue;
}
min=x[1];
for(i=0;i<n;i++){
if(x[i]<=min){
min=x[i];
}
else
continue;
}
me=(maks+min)/2;
a=0;
for(i=0;i<n;i++){
if(x[i]%2==1){
a=a++;
ganjil=a;
}
}
genap=n-ganjil;
//Bagian output
cout<<endl;
cout<<"\t\tJumlah Bil Genap = "<<genap<<endl;
cout<<"\t\tjumlah Bil Ganjil = "<<ganjil<<endl;
cout<<"\t\tJumlah Data = "<<n<<endl;
cout<<"\t\tTotal Data = "<<total<<endl;
cout<<"\t\tRata-rata = "<<rata<<endl;
cout<<"\t\tMedian = "<<me<<endl;
cout<<"\t\tMinimum = "<<min<<endl;
cout<<"\t\tMaksimum = "<<maks<<endl;
cout<<endl<<endl<<endl;
//Finishing
cout<<"\t\t=>Inputkan Data Lagi [Y/y/T/t] : "; cin>>lagi;
if(lagi=='Y' || lagi=='y')
goto atas ;
else if(lagi=='T' || lagi=='t')
exit(0);
else
cout<<"\t\t\t(Input SALAH . . .)";
getch();
return 0;
}
0 komentar:
Posting Komentar