Algoritma Menjumlahkan Deret dengan C++
Mei 8, 2011
Algoritma jumlah deret
{Menjumlahkan deret x }
DEKLARASI
int = x (input)
float = rumus
float = jumlah
float = total (output)
DESKRIPSI
Read(x)
jumlah<--0 total<--0 rumus<--- -1 for(int i=1; i<=x; i++) { rumus<-- (rumus*(-1)) total<-- rumus/i jumlah<-- total if(i==1) then total if(i>1) then +(total) } Write(total)
Program
#include <cstdlib> #include <iostream> using namespace std; class deret { public : int input (); int proses (); void output (); int x; float rumus,jumlah,total; }; int deret::input() { cout<<"Menghitung Jumlah Deret x"<<endl; cout<<"masukan nilai x :"; cin>>x; } int deret::proses() { jumlah=0; total=0; rumus=-1; for(int i=1; i<=x; i++) { rumus=(rumus*(-1)); total=rumus/i; jumlah=total; if(i==1) cout<<"("<<total<<")"; if(i>1) cout<<"+("<<total<<")"; } } void deret::output() { cout<<endl<<endl<<"jumlah deret = "<<jumlah<<endl; } int main(int argc, char *argv[]) { deret n; n.input(); n.proses(); n.output(); system("PAUSE"); return EXIT_SUCCESS; }