[ create a new paste ] login | about

Link: http://codepad.org/VP43s1AP    [ raw code | output | fork | 4 comments ]

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
posted by cuong.luucb8921 on Aug 19
#include<stdio.h>

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

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
posted by Phule on Oct 27

reply
posted by Phule on Oct 27
#include<stdio.h>
#include<conio.h>

int main(){
int n, S;
S = 0;
do{
printf("Nhap n > 1: ");
scanf("%d", &n);
if(n <= 0){
printf("\nVui long nhap so nguyen duong n > 1 !");
}
}while (n <= 1);
for (int i = 1; i <= n; i++){
if (n % i == 0){
S = S + i;
}
}
if(S == n + 1){// Tong cac uoc so cua so nguyen to bang chinh no + 1
printf("\nn la so nguyen to");
}else
printf("\nn khong phai la so nguyen to");
return 0;
}

reply