C程序设计第5章外部类型( extern ).pptVIP

  • 18
  • 0
  • 约2.07万字
  • 约 56页
  • 2019-12-08 发布于广东
  • 举报
* * * * * * * * * #include iostream.h void main() { double p,t,sum_e; int i = 1; p = 1; sum_e = 1; do { p=p*i; // 计算i的阶乘 t=1/ p; sum_e=sum_e+t; i = i + 1; //为计算下一项作准备 }while(t0.00001); coutsum_eendl; } * #include iostream.h #include math.h #includeiomanip.h #include stdlib.h void main() { int max, min,x; x=rand()%101+100; //产生一个[100, 200]之间的随机数x coutsetw(4)x; max = x; min =x; // 设定最大数和最小数 for(int i=1;i10;i++) { x=rand()%101+100; //再产生一个[100, 200]之间的随机数x coutsetw(4)x; if(x max)max = x; // 若新产生的随机数大于最大数,则进行替换 if(x min)min = x; // 若新产生的随机数小于最小数,则进行替换 } coutendl最大数:max,最小数:minendl; //输出最大和最小数 } * #include iostream.h #include math.h #includeiomanip.h void main() { int x,y,z; for(x=0;x=100;x++) //可优化为x=19 for(y=0 ;y100;y++)// 可优化为y=33 { z=100-x-y; if(5*x+3*y+z/3.0==100) coutsetw(5)xsetw(5)ysetw(5)zendl; } } * * #include iostream.h void main() { int score; cout 请输入成绩; cin score; if (score = 90) cout 优 endl; else if( (score = 80) (score 90) ) cout 良 endl; else if( (score = 70) (score 80) ) cout 中 endl; else if( (score = 60) (score 70) ) cout 及格 endl; else cout 不及格 endl; } * #include iostream.h void main( ) { char ch; cinch; ch=(ch=A ch=Z)?(ch+32):ch; //判别ch是否大写字母,是则转换 coutchendl; } * #includeiostream.h void main() { int score; int a; coutInput score(0~100):; cinscore; a=score/10; switch(a) { case 10: case 9: cout 优 endl; break; case 8: cout 良 endl; break; case 7: cout 中 endl; break; case 6: cout 及格 endl; break; default: cout不及格 endl; } } * #include iostream.h void main( ) { int i=1,sum=0; while (i=100) { sum=sum+i; i++; } coutsum=sumendl; } * * * * * * * * * * #include iostream.h void main() { double p,t,sum_e; int i = 1; p = 1; sum_e = 1; do { p=p*i; // 计算i的阶乘 t=1/ p; sum_e=sum_e+t; i = i + 1;

文档评论(0)

1亿VIP精品文档

相关文档