Algoritma :
Fungsi rata (input x : array [1..10] of integer, n : integer) : real
{Diberikan n data kemudian dicari rata-ratanya}
Deklarasi
i, jumlah : integer
Deskripsi
jumlah = 0
for i = 1 to n do
jumlah = jumlah + x[i]
endfor
rata = jumlah/n
Program c++ :
#include <iostream>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;
void rata(int bil []){
int n;
cout<<"Masukkan jumlah data:";
cin>>n;
bil[n];
int rata=0;
int hasil=0;
for(int i=0;i<n;i++){
cout<<"masukkan data ke "<<i<<" : ";
cin>>bil[i];
}
for(int i=0;i<n;i++){
hasil=hasil+bil[i];
}
rata=hasil/n;
cout<<"jumlah total: "<<hasil<<endl;
cout<<"rata-rata : "<<rata;
}
int main(int argc, char** argv) {
int bil [100];
rata(bil);
return 0;
}
Program Raptor :
Comments
Post a Comment