[ create a new paste ] login | about

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

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


float deQuy(int n)
{
	if(n == 1)
		return sqrt(2.0);
	return sqrt(2 + deQuy(n - 1));
}

float deQuyDuoi(int n, float x = sqrt(2.0))
{
	if(n == 1)
		return x;
	return deQuyDuoi(n - 1, sqrt(2.0 + x));
}

float khuDeQuy(int n)
{
	float S;
	S = sqrt((float)2);
	for(int i = 2; i <= n; i++)
	{
		S = sqrt(2 + S);
	}
	return S;
}
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 13: error: expected ';', ',' or ')' before '=' token
In function 'khuDeQuy':
Line 24: error: 'for' loop initial declaration used outside C99 mode


Create a new paste based on this one


Comments: