感觉写得很漂亮,但为什么测试第一个通过不了呢,用VS也不对,能看看错哪了吗
查看原帖
感觉写得很漂亮,但为什么测试第一个通过不了呢,用VS也不对,能看看错哪了吗
967545
gao3051319126楼主2023/4/26 20:06
#include<stdio.h>
#include<math.h>
int zhishu(int i)
{   int count=0;
    for(int j=1;j<=sqrt (i);j++)
    {
        if(i%j==0)
        {
         count+=1;
        }
        if(count>=2)
        break;
    }
    return count;
}
int main()
{
    int a[101],n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
    }
    for(int i=1;i<=n;i++)
    {
        if(zhishu(a[i])<=1)
        {
            printf("%d ",a[i]);
        }
    }
    return 0;
}
2023/4/26 20:06
加载中...