[ create a new paste ] login | about

Link: http://codepad.org/Z4tB1vdG    [ raw code | output | fork | 8 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 + (float)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 Nhi on Dec 19
tại sao lại có float i / (i + 1) vậy ạ
reply
posted by xdnguyenhiepxd on Jan 25
nó cũng như công thức tổng quát.mk ấn giá trị rồi máy tính sẽ tính cho mk từ công thức tổng quát đấy
reply
posted by Tuankhoilua on May 4
#include <iostream>
using namespace std;
int main ()
{
// Tinh S(n)=1/2 + 2/3 + ... + n/n+1
int n;
double Sum = 0;
cout << " n = ";
cin >> n;
if (n < 1)
{
cout << "n Khong the nho hon 1 vui long nhap lai" << endl;
}
else
{
for (double i = 0; i <= n; i++)
{
Sum = Sum + (i/(i+1));
}
cout << "S(n) = " << Sum << endl;

}

system ("pause");
return 0;
}
reply
posted by xdnguyenhiepxd on Jan 25
#include<stdio.h>
#include<conio.h>
int main()
{
int n; float tong,a,b=1;
do
{
printf("Nhap gia tri N=");
scanf("%d",&n);
}
while(n<=1);
for(int i=2;i<=n;i++)
{
a=(float)b/i;
tong=tong+a;
b=i;
}
printf("tong cac gia tri vua nhap la:%f",tong);
}
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) i/(i+1) + s;
}
cout << s;
return 0;
/*HuynhMinhNhat*/
}
reply
posted by incarnation16 on May 21
#include <stdio.h>

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

for (i = 1; i <= n; i++)
{

S = S + (float)i / (i + 1);
}
printf("\nTong la: %f", S);
}
/*Nguyen Quy Minh*/
reply
posted by incarnation16 on May 21
*K co "le"
reply
posted by phaman151087@gmail.com on Aug 25
tại sao phải (float)i vậy thầy.
reply