[ create a new paste ] login | about

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

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

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

	while(i <= n)
	{
		T = T + i;
		S = S + 1.0 / T;
		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 dongthevo on Aug 18
#include<iostream>
#include<cmath>
using namespace std;
int main()
{ //S(n) = 1 + 1/1 + 2 + 1/ 1 + 2 + 3 + ….. + 1/ 1 + 2 + 3 + …. + N
float S=0,n,x=1,a=0,dem=1;
for(;S==0;S=0,dem=1)
{
cout<<"Nhap n:";
cin>>n;
for(;dem<=n;++dem,x=1,a=0)
{
for(;x<=dem;++x)
{
a=a+x;
}
S=S+1/a;
}
cout<<"S="<<S;
cout<<endl;
}
return 0;
}
reply
posted by ahuyscpy5662 on May 26
#include <iostream>
using namespace std;
int main()
{
int i,n,s ;
cin>> n;
s=0;
float p=0;
for (i=1;i<=n;i++)
{
s=s+i;
p=(float)p+1.0/s;
}
cout<< (float) p;
reply