#include
#include
void isPrime(int m) //判断是不是素数
{
int i;
int a=sqrt(m);
for(i=2;i<=a;i++)
{
if(m%i==0)//不是素数
{
printf("sample output:\n");
printf("n\n",m);
break;
}
else
{
printf("sample output:\n");
printf("y\n");
break;
}
}
}
void main()
{
int year,month,day,sum;
printf("sample input:\n");
scanf("%d %d %d",&year,&month,&day);
sum=year*1000+month*100+day;
isPrime(sum);
}
还没23:00,希望可以帮到你,临时写的,因为时间关系,注解可以再问我。
#include
#include
#include
int main()
{
char year[5], mon[3], day[3];
char string[9]={0};
char zero[]="0";
int test=0;
scanf("%s%s%s", year, mon, day);
int n_mon=atoi(mon);
int n_day=atoi(day);
strcpy(string, year);
if(n_mon <= 9){
strcat(string, zero);
}
strcat(string, mon);
if(n_day <= 9){
strcat(string, zero);
}
strcat(string, day);
int n_string=atoi(string);
for(int i=2; i<=n_string-1; i++){
if(n_string%i==0){
test=1;
break;
}
}
if(test==1){
printf("n\n");
}
if(test==0){
printf("y\n");
}
return 0;
}
#include
#include
int isprime(int n)
{
int i;
for (i = 2; i < (int)sqrt(n); i++)
{
if (n % i == 0)
return 0;
}
return 1;
}
void main()
{
int year, month, day, number;
scanf("%d %d %d", &year, &month, &day);
number = year * 10000 + month * 100 + day;
if (isprime(number))
printf("y\n");
else
printf("n\n");
}
#include "stdafx.h"
#include
#include
void prime(int num )
{
int i=2,x=sqrt(num);
do{ if(num%i==0) break; }while(i++<=x);
if(i<=x) printf("n\n");
else printf("y\n");
}
void main()
{
int date,year,month,day;
printf("Please enter the date:");
scanf("%d%d%d",&year,&month,&day);
date=year*10000+month*100+day;
prime(date);
}
#include
#include
main()
{
int year,month,day,num,i,k;
printf("please input a date:\n");
scanf("%d %d %d",&year,&month,&day);
num=10000*year+100*month+day;
for(i=2;i<=sqrt(num);i++)
{
if(num%i!=0)
k=1;
else
{k=0;
break;
}
}
if(k)
printf("Y");
else
printf("N");
}