| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 904 人关注过本帖
标题:C哪里错啦这是 一个题目复制过来的
只看楼主 加入收藏
JJGA
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2021-4-11
结帖率:0
收藏
 问题点数:0 回复次数:0 
C哪里错啦这是 一个题目复制过来的
main()
{
    int m, i ,k;
scanf(“%d”,&m);
k=sqrt(m+1);
for(i=2; i<=k; i++)
        if(m%i = = 0)
            break;
if( i >= k+1)
printf(“%d is a prime number\n”,m);
else
printf(“%d is not a prime number\n”,m);
  }
程序运行,输入99,输出结果为:
搜索更多相关主题的帖子: number 输入 复制 printf not 
2021-10-11 15:51
自由而无用
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:14
帖 子:61
专家分:1456
注 册:2021-8-9
收藏
得分:0 
//online parser: https://www.bccn.net/run/
程序代码:
#include <stdio.h>
#include <math.h>

int main(int argc, char *argv[])
{
    int m, i ,k;
    
    for (m = 0; m <= 125; m++) {
        for (i = 2, k = sqrt(m + 1); i <= k; i++) 
            if(m % i == 0) break;
        if (i >= k + 1)
            printf("%d is a prime number\n", m);
        else 
            printf("%d is not a prime number\n", m);
    }
    
    return 0;
}


output sample:
0 is a prime number
1 is a prime number
2 is a prime number
3 is a prime number
4 is not a prime number
5 is a prime number
6 is not a prime number
7 is a prime number
8 is not a prime number
9 is not a prime number
10 is not a prime number
11 is a prime number
12 is not a prime number
13 is a prime number
14 is not a prime number
15 is not a prime number
16 is not a prime number
17 is a prime number
18 is not a prime number
19 is a prime number
20 is not a prime number
21 is not a prime number
22 is not a prime number
23 is a prime number
24 is not a prime number
25 is not a prime number
2021-10-11 16:20
快速回复:C哪里错啦这是 一个题目复制过来的
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.012646 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved