[ create a new paste ] login | about

Link: http://codepad.org/EjLDqdEP    [ raw code | output | fork ]

C, pasted on Apr 21:
#include<stdio.h>
#include<conio.h>

int deQuyPhiTuyen(int n)
{
	if(n == 1)
		return 1;

	int tich = 1;
	for(int i = 1; i <= n; i++)
	{
		tich *= i;
	}
	return deQuyPhiTuyen(n - 1) + tich;
}

int khuDeQuy(int n)
{
	int i;
	long S, P;
	S = 0;
	P = 1;
	i = 1;
	while(i <= n)
	{
		P = P * i;
		S = S + P;
		i++;
	}
	return S;
}
// --------------------------------------------
int main()
{
	int n;
	printf("\nNhap n: "); scanf("%d", &n);

	printf("\nDe quy phi tuyen = %d", deQuyPhiTuyen(n));
	printf("\nKhu de quy = %d", khuDeQuy(n));


	getch();
	return 0;
}


Output:
1
2
3
Line 17: error: conio.h: No such file or directory
In function 'deQuyPhiTuyen':
Line 10: error: 'for' loop initial declaration used outside C99 mode


Create a new paste based on this one


Comments: