Jumat, 25 Maret 2016

Kasus 4.4 - Mencari rata-rata

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

Flowchart :

Tidak ada komentar:

Posting Komentar