#include <cstdlib>
#include <iostream>
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 Rekursif = " << jumlah;
cout << endl;
cout << endl;
return jumlah;
}
int main(int argc, char *argv[])
{
cout << "\t\t\tSlamet Islan Al Hidayah\n";
cout << "\t\t\t\t10018075\n";
cout << "\t\t\t\t B\n";
cout << endl;
cout << endl;
cout << " Program Menghitung Jumlah dari \n";
cout << " Rumus 1-(1/2)+(1/3)-(1/4)+...+(1/n) \n";
cout << endl;
cout << endl;
cout << " Masukkan Nilai n : ";
hitung deret;
deret.input();
deret.proses();
system("PAUSE");
return EXIT_SUCCESS;
}
#include <iostream>
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 Rekursif = " << jumlah;
cout << endl;
cout << endl;
return jumlah;
}
int main(int argc, char *argv[])
{
cout << "\t\t\tSlamet Islan Al Hidayah\n";
cout << "\t\t\t\t10018075\n";
cout << "\t\t\t\t B\n";
cout << endl;
cout << endl;
cout << " Program Menghitung Jumlah dari \n";
cout << " Rumus 1-(1/2)+(1/3)-(1/4)+...+(1/n) \n";
cout << endl;
cout << endl;
cout << " Masukkan Nilai n : ";
hitung deret;
deret.input();
deret.proses();
system("PAUSE");
return EXIT_SUCCESS;
}
0 Response to " (Class) Menghitung Jumlah Deret "
Post a Comment