Kamis, 05 April 2012

Alpro-pertemuan 4 (Mencari rata-rata dari n bilangan bulat positif)




flowchart..... ^_^


this's the program....
#include <iostream>
#include <string>


using namespace std;
int main()
{
   string raptor_prompt_variable_zzyz;
   int i;
   int n;
   int jum;
   int x;
   float rata;

   raptor_prompt_variable_zzyz ="n = ";
   cout << raptor_prompt_variable_zzyz << endl;
   cin >> n;
   jum =0;
   i =1;
   while (!(i>n))
   {
      raptor_prompt_variable_zzyz ="x = ";
      cout << raptor_prompt_variable_zzyz << endl;
      cin >> x;
      jum =jum+x;
      i =i+1;
   }
   rata =jum/n;
   cout <<"jumlah = "<< jum << endl;   cout <<"rata-rata = "<< rata << endl;
   system("pause");
   return 0;
}

Tidak ada komentar:

Posting Komentar