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 &lt;cstdlib&gt;
#include &lt;iostream&gt;
using namespace std;
class deret {
public :
int input ();
int proses ();
void output ();
int x;
float rumus,jumlah,total;
};
int deret::input()
{
cout&lt;&lt;"Menghitung Jumlah Deret x"&lt;&lt;endl;
cout&lt;&lt;"masukan nilai x :";
cin&gt;&gt;x;
}
int deret::proses()
{
jumlah=0;
total=0;
rumus=-1;
for(int i=1; i&lt;=x; i++)
{
rumus=(rumus*(-1));
total=rumus/i;
jumlah=total;
if(i==1)
cout&lt;&lt;"("&lt;&lt;total&lt;&lt;")";
if(i&gt;1)
cout&lt;&lt;"+("&lt;&lt;total&lt;&lt;")";
}
}
void deret::output()
{
cout&lt;&lt;endl&lt;&lt;endl&lt;&lt;"jumlah deret = "&lt;&lt;jumlah&lt;&lt;endl;
}
int main(int argc, char *argv[])
{
deret n;
n.input();
n.proses();
n.output();
system("PAUSE");
return EXIT_SUCCESS;
}
Comment here