编写一个函数primeNum(int x),功能是判别一个数是否为素数
#include<stdio.h>intprimeNum(intx){intm;scanf_s("%d",&x);for(m=2;m>1&&m<x;m++){if(x%m...
#include<stdio.h>
int primeNum(int x)
{
int m;
scanf_s("%d", &x);
for (m = 2; m > 1 && m < x; m++)
{
if (x%m != 0)
return 1;
else
return 0;
}
}
void main()
{
int a, b;
printf("Please input a number:");
scanf_s("%d", &a);
b=primeNum(a);
if (b = 1)
printf("%d is a prime number.\n", a);
else printf("$d is not a prime number.\n", a);
}
大神帮帮忙看看哪里有问题,编译不过 展开
int primeNum(int x)
{
int m;
scanf_s("%d", &x);
for (m = 2; m > 1 && m < x; m++)
{
if (x%m != 0)
return 1;
else
return 0;
}
}
void main()
{
int a, b;
printf("Please input a number:");
scanf_s("%d", &a);
b=primeNum(a);
if (b = 1)
printf("%d is a prime number.\n", a);
else printf("$d is not a prime number.\n", a);
}
大神帮帮忙看看哪里有问题,编译不过 展开
展开全部
#include<stdio.h>
#define scanf_s scanf
int primeNum(int x){
int m;
for (m = 2; m > 1 && m <= x; m++)
if (x%m == 0)
break;
if(m==x)
return 1;
else
return 0;
}
void main(){
int a, b;
printf("Please input a number:");
scanf_s("%d", &a);
b=primeNum(a);
if (b == 1)
printf("%d is a prime number.\n", a);
else
printf("%d is not a prime number.\n", a);
}
错误太多,就不一一指出了,直接附上改好的代码。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询