码迷,mamicode.com
首页 > 编程语言 > 详细

【C语言程序】输出前50个素数

时间:2017-10-03 13:34:00      阅读:200      评论:0      收藏:0      [点我收藏+]

标签:com   技术   prime   turn   ret   代码   png   http   ++   

#include <stdio.h>
#include <stdlib.h>

int main(void) {
 int x=2;
 int i,cnt=0;
 while(cnt<50){
  int isprime=1;
  for(i=2;i<x;i++){
   if(x%i==0){
   isprime=0;
   
  }}if(isprime==1){
   printf("%d ",x);
   cnt ++;
  }
    x++;
 }
 return 0;
}

代码运行如下:

技术分享

【C语言程序】输出前50个素数

标签:com   技术   prime   turn   ret   代码   png   http   ++   

原文地址:http://www.cnblogs.com/levelstrcpy/p/7623625.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!