一个C语言的填空 麻烦解解

来源:百度知道 编辑:UC知道 时间:2024/06/30 06:12:26
编写一个函数int IsPrime(int n),如果n是素数,返回1,否则返回0,另外编写一个函数void NearestPrime(int b, int *a, int *c),功能是求出比b小的第一个素数和比b大的第一个素数,分别存入指针a和指针c指向的存储单元。在main()函数中输入一个大于2的整数,输出比它小的第一个素数和比它大的第一个素数。
#include <stdio.h>
#include <math.h>
int IsPrime(int n)
{
int i,d;
d = (int)sqrt((double)n);
for(i= ; i<=d i++)
{
if( ) return 0;
}
;
}
void NearestPrime(int b, int *a, int *c)
{
*a=b-1;
while(*a>=2 && IsPrime(*a)==0) (*a)--;
*c= ;
while( ) (*c)++;
}
void main()
{
int b,a,c;
printf("请输入一个大于2的整数:");
scanf("%d", &b);
if( ) printf("输入错误,必须输入大于2的整数!\n");
else
{
;
printf("比%d大的第一个素数是%d;比%d大的第一个素数是%d。\n", b, a, b, c);
}
}

#include <stdio.h>
#include <math.h>
int IsPrime(int n)
{
int i,d;
d = (int)sqrt((double)n);
for(i=2 ; i<=d;i++)
{
if( n%i==0) return 0;
}
return 1;
}
void NearestPrime(int b, int *a, int *c)
{
*a=b-1;
while(*a>=2 && IsPrime(*a)==0) (*a)--;
*c=b+1;
while(IsPrime(*c)==0) (*c)++;
}
void main()
{
int b,a,c;
printf("请输入一个大于2的整数:");
scanf("%d", &b);
if(b<=2) printf("输入错误,必须输入大于2的整数!\n");
else
{
NearestPrime(b,&a,&c);
printf("比%d小的第一个素数是%d;比%d大的第一个素数是%d。\n", b, a, b, c);
}
}

没时间,烦着呢。捣什么乱

函数isPrime中:
for(i=2;i<=d;i++) {
if ((n % i)==0) return 0;
}
return 1;
函数NearestPrime中:
*c=b+1;
while(isPrime(*c)==0) (*c)++;
函数main中:
if(b<3) printf(...
else {
NearestPrime(b, &a, &c);

请教一个C语言的填空题,麻烦解释一下,谢谢!!以下的for循环,循环次数______。 请教一个C语言的填空题,麻烦解释一下,谢谢!!如果已定义:float aa=1234.5678; 则执行 C语言的几个填空 C语言的填空题: 请教一个C语言程序填空T? ·请教一个C语言的填空题,麻烦解释一下,谢谢!!下面程序的执行完后全局变量n的值是______。 请教一个C语言的填空题,麻烦解释一下,谢谢!!执行后p和q所指向的单元的内容分别为______。 请教一个c语言问题,麻烦解释一下,谢谢!!使用指向数组元素的指针输出二维数组的所有元素,请填空。 请教一个C语言的填空题,麻烦解释一下,谢谢!!表达式(a=4,2)运算后 , a+1的值是______。 请教一个C语言的填空题,麻烦解释一下,谢谢!!分析以下程序段,while 循环执行的次数是______次。