Hitunglah nilai dari :
Flowchart :
Klik gambar untuk perbesar |
C++:
#include <iostream>
#include <string>
using namespace std;
int main()
{
int hasil;
int n;
int i;
cout<<"Masukkan n = ";
cin >> n;
i =2;
hasil =1;
while (!(i>n))
{
if (i % 2==0)
{
hasil =hasil-(1/i);
}
else
{
hasil =hasil+(1/i);
}
i =i+1;
}
cout << "Hasil-nya = "<<hasil << endl;
system("PAUSE");
return 0;
}
#include <string>
using namespace std;
int main()
{
int hasil;
int n;
int i;
cout<<"Masukkan n = ";
cin >> n;
i =2;
hasil =1;
while (!(i>n))
{
if (i % 2==0)
{
hasil =hasil-(1/i);
}
else
{
hasil =hasil+(1/i);
}
i =i+1;
}
cout << "Hasil-nya = "<<hasil << endl;
system("PAUSE");
return 0;
}
0 komentar:
Posting Komentar