[ create a new paste ] login | about

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

C, pasted on Aug 18:
#include<stdio.h>
#include<conio.h>

int main()
{
	int i, n;
	printf("\nNhap n: ");
	scanf("%d", &n);

	if(n < 2)
		printf("\nSo %d khong phai la so nguyen to", n);
	else if(n == 2)
		printf("\nSo %d la so nguyen to", n);
	else if(n % 2 == 0)
		printf("\nSo %d khong phai la so nguyen to", n);
	else
	{
		for(i = 3; i <= n; i+=2)
		{
			if(n % i == 0)
				break;
		}
		if(i == n)
			printf("\nSo %d la so nguyen to", n);
		else
			printf("\nSo %d khong phai la so nguyen to", n);
	}
		


	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 hai on Dec 26
#include<iostream>
#include<cmath>
using namespace std;
bool kiem_tra_n(int n) {
if (n < 2)
{
return false;
}
else
{
if (n % 2 == 0)
{
return false;
}
else
{
for (int i = 2; i < n; i++)
{
if (n % i == 0)
{
return false;
}
}
}
}

return true;
}
int main()
{
int n;
cout << "\nnhap n: ";
cin >> n;
if (kiem_tra_n(n) == true)
{
cout << "\nn la so nguyen to";
}
else
{
cout << "\nn kh phai la so nguyen to";
}
return 0;
}
reply