Algoritma Pemrograman
Koding C++
#include <iostream>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char** argv) {
int bnyk,i, data[100],jumlah=0;
float hasil;
cout<<"Banyak data : ";
cin>>bnyk;
for(i=0;i<bnyk;i++){
cout<<"Nilai mahasiswa ke- ["<<i+1<<"] : ";
cin>>data[i];
}
system("cls");
for(i=0;i<bnyk;i++){
cout<<"Nilai mahasiswa ke- "<<i+1<<": "<<data[i]<<endl;;
}
for(i=0;i<bnyk;i++){
jumlah+=data[i];
}cout<<"Jumlah : "<<jumlah<<endl;
hasil=jumlah/bnyk;
cout<<"Rata-rata = "<<hasil;
return 0;
}
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char** argv) {
int bnyk,i, data[100],jumlah=0;
float hasil;
cout<<"Banyak data : ";
cin>>bnyk;
for(i=0;i<bnyk;i++){
cout<<"Nilai mahasiswa ke- ["<<i+1<<"] : ";
cin>>data[i];
}
system("cls");
for(i=0;i<bnyk;i++){
cout<<"Nilai mahasiswa ke- "<<i+1<<": "<<data[i]<<endl;;
}
for(i=0;i<bnyk;i++){
jumlah+=data[i];
}cout<<"Jumlah : "<<jumlah<<endl;
hasil=jumlah/bnyk;
cout<<"Rata-rata = "<<hasil;
return 0;
}
EmoticonEmoticon