[ create a new paste ] login | about

Link: http://codepad.org/WzxqC2NE    [ raw code | output | fork | 3 comments ]

C, pasted on Sep 6:
#include<stdio.h>
#include<conio.h>

int main()
{
	int N, d;
	printf("\nNhap N: ");
	scanf("%d", &N);
	if(N < 2)
		printf("\nSo %d khong 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 la so nguyen to", N);
			else
			{
				d = 3;
				while(d <= N)
				{
                    if(N % d == 0)
						break;
					d = d + 2;
				}
				if(d == N)
					printf("\nSo %d la so nguyen to", N);
				else
					printf("\nSo %d khong 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 manhha on Feb 26
// kiem tra 1 so co phai so nguyen to hay khong
#include <stdio.h>
#include <conio.h>
int main()
{
int n;
printf("Nhap vao n", n);
scanf("%d", &n);
printf("So n co phai so nguyen to hay khong? \n");

if (n < 2)
{
printf("n khong phai so nguyen to");
}
else
{
bool check = true;

for (int i = 2; i < n; i++)
{

if (n % i == 0)

check = false;

}

if (check == false)
{
printf("Sai!");
}

else
{
printf(" Dung!");
}

}
getch();
return 0;

}


reply
posted by yonnon on Jul 12
#include<bits/stdc++.h>

using namespace std;
int main(){
int n;
cout <<"Enter your sentence: ";
cin >> n;
if(n == 1 || n==2 || n==3){
cout<<"True";
return 0;
}
for(int i=2; i<=sqrt(n);++i){
if(n%i==0){
cout<<"False ";
return 0;
}
else {
cout<<"True";
return 0;
}
}
}
reply
posted by cuong.luucb8921 on Sep 1
#include<stdio.h>

int main(){
int n;

do
{
printf("Nhap vap n:\n");
scanf("%d",&n);
if(n < 1)
{
printf("n phai lon hon bang 1\n");
}
}while(n < 1);

int i;
int s=0;

for(i=1;i<=n;i++)
{
if(n%i==0)
{
s = s+1;
}
}

if(s==2)
{
printf("%d la so nguyen to",n);
}
else
{
printf("%d khong la so nguyen to",n);
}
return 0;
}

reply