[ create a new paste ] login | about

Link: http://codepad.org/MBaChKMc    [ raw code | output | fork | 4 comments ]

C, pasted on Aug 17:
#include<stdio.h>
#include<conio.h>

int main()
{
	int i, n;
	float S;
	S = 0;
	i = 1;
	do
	{
		printf("\nNhap n: ");
		scanf("%d", &n);
		if(n < 1)
		{
			printf("\nN phai lon hon hoac bang 1. Xin nhap lai !");
		}
	}while(n < 1);

	while(i <= n)
	{
		S = S + 1.0 / (i * (i + 1));
		i++;
	}
	printf("\nTong la %f", S);

	getch();
	return 0;
}


Output:
1
Line 17: error: conio.h: No such file or directory


Create a new paste based on this one


Comments:
posted by Tuankhoilua on May 4
#include <iostream>
using namespace std;
int main ()
{
// Tinh S=1/1*2 + 1/2*3 + ... + 1/( n * (n + 1))
double n , nA = 1;
double Sum = 0;

cout << "Vui long nhap n = ";
cin >> n;
if (n < 1)
{
cout << " n khong the < 1 vui long nhap lai";
}
else
{
Sum += 1/(n* (n + 1));
n++;
}
cout << " S(n) = " << Sum << endl;

system ("pause");
return 0;
}
reply
posted by tydonutt on Oct 2
3
reply
posted by MinhNhat on Feb 1
#include <iostream>
using namespace std;

int main ()
{
int n;
cin >> n;
double s = 0;
for (int i = 1; i <= n; i++)
{
s = (double) 1 /(i*(i+1)) + s;
}
cout << s;
return 0;
}
reply
posted by 20223768 on Sep 9
#include <iostream>
using namespace std;
int main()
{
int n; cin >>n;
double s=0;
for (int i=1; i<=n; i++)
s=s+1.0/i*(i+1);
cout << s;
return 0;
}
reply