[ create a new paste ] login | about

Link: http://codepad.org/x5beSxoE    [ raw code | output | fork | 1 comment ]

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

int main()
{
	int i, n;
	long S, P;
	S = 0;
	P = 1;
	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)
	{
		P = P * i;
		S = S + P;
		i++;
	}
	printf("\nTong la %d",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 17
#include<iostream>
#include<cmath>
using namespace std;
int main(){ //Tinh S(n) = 1 + 1.2 + 1.2.3 + … + 1.2.3….N
int S=0,n,x;
for(;S==0;S=0)
{ cout<<"Nhap n:";
cin>>n;
for(int dem=1,z=1,x=1;dem<=n;++dem,x=1)
{
for(;x<=dem;++x)
{
z=z*x;
}
S=S+z;
z=1;
}
cout<<"S="<<S;
cout<<endl;
}
return 0;
}
reply