ade10018043
hai gan...bertemu lagi dengan saya nich dalam acara upgrade program..hehehe

oke kali ini saya akan membahas tentang membuat fungsi secara INTERATIF..

oke ini dia programnya..agan agan bisa melihat sendiri yaa.. :)

#include
#include

using namespace std;

class hitung
{

public:
int proses();
void input();

private:
int n;
float rumus,jumlah,total;
};

void hitung::input()
{
cin >> n;
cout << endl; } int hitung::proses() { jumlah = 0; total = 0; rumus = -1; for(int j=1; j<=n; j++){ rumus = (rumus * (-1)); total = rumus / j; jumlah+= total; if(j==1) cout << " ( " << total << " ) "; if( j > 1)
cout << " + ( " << total << " ) ";
}

cout << endl << endl << " Jumlah INTERATIF = " << jumlah;
cout << endl;

return jumlah;
}

int main(int argc, char *argv[])
{
cout << " Program Menghitung Jumlah dari Dumus 1-(1/2)+(1/3)-(1/4)+...+(1/n) ";
cout << endl;
cout << endl;
cout << " Masukkan Nilai n : ";

hitung deret;
deret.input();
deret.proses();

system("PAUSE");
return EXIT_SUCCESS;
}
Label: | edit post
0 Responses

Posting Komentar