"Menghitung rerata"
#include <iostream.h>
#include <conio.h>
main()
{
int tombol,cacah=0;
float nilai,jumlah=0,rerata;
clrscr();
cout<<"Menghitung rerata nilai\n";
cout<<"Masukan nilai,"<<"isi nilai negatif jika selesai\n\n";
do
{
cacah ++;
cout<<"data ke-"<<cacah<<"=";
cin>>nilai;
jumlah=jumlah+nilai;
}
while(nilai >=0);
rerata=jumlah/cacah;
cout<<endl;
cout<<"==============================="<<endl;
cout<<"\nBanyaknya data = "<<cacah;
cout<<endl;
cout<<"-------------------------------"<<endl;
cout<<"\nJumlah = "<<jumlah;
cout<<endl;
cout<<"-------------------------------"<<endl;
cout<<"\nRerata = "<<rerata;
cout<<endl;
cout<<"==============================="<<endl;
getch();
}
Comments
Post a Comment