Kasus 4.3 Carilah rata-rata dari n bilangan bulat positif.





Algoritma :
·        Deklarasi variable i, n, jumlah, dan x dengan tipe data integer,
·        bilangan untuk n,
·        Proses menggunakan rumus rata-rata yaitu jumlah data dibagi banyaknya data,
·        Outputkan.

#include <iostream>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;
int main(int argc, char** argv) {
    int i, n, jumlah, x;
    float rata;
    cout<<"Banyak Data : "; cin>>n;
    jumlah=0;
    for (i=1; i<=n; i++){
    cout<<"Data ke "<<i<<" : "; cin>>x;
    jumlah +=x;
}
rata=(float)jumlah/n;
cout<<"Rata-rata = "<<rata;
    return 0;
}

 






Previous
Next Post »
Copyright © 2015 Bettong'rs All Right Reserved
Created by Arlina Design Powered by Blogger