思路:从3到100依次判断是否素数,如果是累加求和,最后输出累加和。 参考代码: #include<stdio.h>int main(){ int i,j,flg,sum=0; for(i=3;i<=100;i++){ flg=1; for(j=2;j
include <stdio.h> define N 100 void main(){ int k;printf("3到100间的素数为:\n");for (int j=3;j<N;j++){ k=0;for(int i=2;i<j;i++)if(j%i==0) k=1;if(k==0) printf("%d ",j);} printf("\n");}
include <stdio.h> int isprime(int n){ int i;for(i=2; i*i<=n; i++)if(n%i==0)return 0;return 1;} int main(){ int i,n=0;printf("3到100的素数:\n");for(i=3; i<100; i++)if(isprime(i)){ printf("%d ",i);n++;} printf("\n个数=%d\n",n);return 0...
#include <stdio.h>#define N 100void main(){ int k; printf("3到100间的素数为:\n"); for (int j=3;j<N;j++) { k=0; for(int i=2;i<j;i++) if(j%i==0) k=1; if(k==0) printf("%d ",j); } printf("\n");} xdhydn | 发布于2010-12-06 举报| 评论 0 2 #inc...
stdio.h"include<math.h> int main(){ int n,i,k;for(n=3;n<=100;n+=2){ k=sqrt(n);for(i=2;i<=k;i++)if(n%i==0)break;if(i>k)printf("%d ",n);} } /*运行结果:3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 / ...
输出3-100之间的所有素数并统计个数:include "stdio.h"include "math.h"void main(){ int x,y,num=0;for(x=3;x<=100;x++){ for(y=2;y<=sqrt(x);y++)if(x%y==0)break;if(y>sqrt(x)){ printf("%d\n",x);num++;} } printf("3-100之间的素数有%d个!\n",num);} ...
include <stdio.h>#include <math.h>int prime(int n) {int i,flag = 1;if(n < 2) return 0;for(i = 2;i <= sqrt(n) && flag; ++i)flag = n%i;return flag;}int main() {int i,n = 300,cnt = 0;;for(i = 3; i <= n; ++i) {if(prime(i)) {++cnt;printf("...
include<math.h>main(){ int i,j,a[101]; for(i=1;i<=100;i++) a[i]=i;for(i=2;i<sqrt(100);i++) for(j=i+1;j<=100;j++) { if(a[i]!=0&&a[j]!=0) if(a[j]%a[i]==0) a[j]=0; }printf("\n");for(i=2,n=0;i<=100...
int shu(long unsigned num) //判断素数函数,是,返回1.否,0 { int t,i;t=sqrt(num)+1;for(i=2;i<t;i++){ if(num%i==0)break;} return i==t;} int main(){ int i,k=0,n=300;for(i=3;i<n;i++)if(shu(i)) //是素数 { k++;printf("%.3d ",i); //格式输出,...
循环部分:for(i=3;i<=100;i++){ for(j=2;j