[ create a new paste ] login | about

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

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

float deQuy(int n)
{
	if(n == 1)
		return 0.5;
	return 1.0 / (1 + deQuy(n - 1));
}

float deQuyDuoi(int n, float x = 0.5)
{
	if(n == 1)
		return x;
	return deQuyDuoi(n - 1, 1.0 / (1 + x));
}

float khuDeQuy(int n)
{
	float tong = 0.5;
	for(int i = 2; i <= n; i++)
	{
		tong = 1.0 / (1 + tong);
	}
	return tong;
}
int main()
{
	int n;
	printf("\nNhap n: "); scanf("%d", &n);

	printf("\nDe quy %d = %f", n, deQuy(n));
	printf("\nDe quy duoi %d = %f", n, deQuyDuoi(n));
	printf("\nKhu de quy %d = %f", n, khuDeQuy(n));

	getch();
	return 0;
}


Output:
1
2
3
4
Line 17: error: conio.h: No such file or directory
Line 11: error: expected ';', ',' or ')' before '=' token
In function 'khuDeQuy':
Line 21: error: 'for' loop initial declaration used outside C99 mode


Create a new paste based on this one


Comments: