第4章 语句与程序流程.pptVIP

  • 3
  • 0
  • 约6.94千字
  • 约 34页
  • 2018-06-14 发布于福建
  • 举报
第4章 语句与程序流程

例:判定a至b之间的数是否为素数。 ? 解法1:(对a至b之间的偶数不进行判定,因偶数不是素数) 第四章 语句和程序流程 #includeiostream.h #includeiomanip.h #includemath.h void main() { long a,b,l=0;//l为素数个数 coutplease input two numbers:\n; cinab; coutprimes fromatobis:\n; 第四章 语句和程序流程 if(a%2==0) a++; for(long m=a;m=b;m+=2)//步长为2 { int sqrtm=sqrt(m); int i; for(i=2;i=sqrtm;i++) if(m%i==0) break; 第四章 语句和程序流程 if(sqrtmi)//素数 { if(l++%i==0) coutendl;

文档评论(0)

1亿VIP精品文档

相关文档