[ create a new paste ] login | about

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

C, pasted on Sep 14:
#include<stdio.h>
#include<conio.h>
#include<math.h>
// nguyên tố => true
bool KiemTraNguyenTo(int n)
{
	if (n < 2)
	{
		return false;
	}
	else if (n > 2)
	{
		if (n % 2 == 0)
		{
			return false;
		}
		for (int i = 3; i <= sqrt((float)n); i += 2)
		{
			if (n % i == 0)
			{
				return false;
			}
		}
	}
	return true;
}

void LietKeNguyenTo(int n)
{
	for(int i = 2; i < n; i++)
	{
		if(KiemTraNguyenTo(i) == true)
			printf("%4d", i);
	}
}
int main()
{
	int n;
	printf("\nNhap n: ");
	scanf("%d", &n);

	LietKeNguyenTo(n);

	getch();
	return 0;
}


Output:
1
2
3
4
5
6
7
Line 17: error: conio.h: No such file or directory
Line 5: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'KiemTraNguyenTo'
In function 'LietKeNguyenTo':
Line 30: error: 'for' loop initial declaration used outside C99 mode
Line 32: error: 'true' undeclared (first use in this function)
Line 32: error: (Each undeclared identifier is reported only once
Line 32: error: for each function it appears in.)


Create a new paste based on this one


Comments:
posted by vu on May 19

reply