While Bersarang

contoh :

#include <stdio.h>
#include <conio.h>
#include <iostream.h>
main ()
{
            int i,n;
            float nilai,jumlah,rata;
            char lagi;
            lagi ='y';
            while (lagi=='y')
            {
                        cout<<"Masukkan Banyak Data=";
                        cin>>n;
                        i=1;
                        jumlah=0;
                        while (i<=n)
                        {
                                    cout<<"Masukkan Nilai Ke-"<<i<<"=";
                                    cin>>nilai;
                                    jumlah = jumlah + nilai;
                                    i=i+1;
                        }
                        rata=jumlah/n;
                        cout<<"Banyak Data="<<n<<endl;
                        cout<<"Total Nilai="<<jumlah<<endl;
                        cout<<"Rata-rata Nilai="<<rata<<endl;
                        cout<<endl;
                        cout<<"Mau Coba Lagi [y/t]=";
                        cin>>lagi;
            }
            getch();
}

0 komentar:

Statistik