[ create a new paste ] login | about

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

C, pasted on Aug 20:
#include<stdio.h>
#include<conio.h>
#include<math.h>
int main()
{
	int i, n;
	float S;
	do
	{
		printf("\nNhap n(n >= 1): ");
		scanf("%d", &n);

		if(n < 1)
		{
			printf("\nn phai >= 1. Xin nhap lai !");
		}
	}while(n < 1);

	S = sqrt((float)2);
	for(i = 2; i <= n; i++)
	{
		S = sqrt(2 + S);
	}
	printf("\nTong S = %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 lehoangnam on Feb 9
#include <iostream>
//#include <math.h>
using namespace std;
float tong(int n)
{
float tong = 2;
for (int i = 1;i < n;i++)
tong = sqrt(tong) + 2;
return sqrt( tong);
}
int main()
{
int n;
cout << endl << "Nhap vao n : ";
cin >> n;
cout<<endl<<tong(n);
}
reply
posted by ptien215 on Sep 26
Có ai giải thích giúp mình tại sao i chạy từ 2 không ạ?

reply