C 练习实例12
C 语言教程
· 2019-02-21 14:58:42
题目:判断101到200之间的素数。
程序分析:判断素数的方法:用一个数分别去除2到sqrt(这个数),如果能被整除, 则表明此数不是素数,反之是素数。
实例
// Created by www.codercto.com on 15/11/9.
// Copyright © 2015年 码农教程. All rights reserved.
//
#include <stdio.h>
int main()
{
int i,j;
int count=0;
for (i=101; i<=200; i++)
{
for (j=2; j<i; j++)
{
// 如果j能被i整出在跳出循环
if (i%j==0)
break;
}
// 判断循环是否提前跳出,如果j<i说明在2~j之间,i有可整出的数
if (j>=i)
{
count++;
printf("%d ",i);
// 换行,用count计数,每五个数换行
if (count % 5 == 0)
printf("\n");
}
}
return 0;
}
以上实例输出结果为:
101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199
点击查看所有 C 语言教程 文章: https://codercto.com/courses/l/17.html
Head First Rails
David Griffiths / O'Reilly Media / 2008-12-30 / USD 49.99
Figure its about time that you hop on the Ruby on Rails bandwagon? You've heard that it'll increase your productivity exponentially, and allow you to created full fledged web applications with minimal......一起来看看 《Head First Rails》 这本书的介绍吧!