C++课后答案完整版.docVIP

  • 4
  • 0
  • 约2.84万字
  • 约 41页
  • 2023-03-30 发布于湖北
  • 举报
第三章 //1.根据下面函数表达式编写一个程序,实现输入x的值后,能计算并输出相应的函数值y: #includeiostream.h void main(void) { double x,y; cout请输入x: ; cinx; if(x0) y=x*x; else if(x=0x1) y=2.5*x-1; else y=3*x+1; coutx=x\ty=yendl; } //2.设计一个程序,要求:对从键盘输入的一个不多于5位的正整数,能输出它的位数并输出它的各位数字之和。 #includeiostream.h void main(void) { int x,count=0,sum=0; cout请输入x: ; cinx; coutx是; while(x) { sum=sum+x%10; x=x/10; count++; } coutcount位数, 其位数之和为: sumendl; } //编程计算s=1! +2! +3! +...+ n! ,n的值从键盘输入,要求输出n和s的值。 #includeiostream.h void main(void) { int n; double t=1, s=0; cout请输入n: ; cinn; for(int i=1;i=n;i++) { t=t*i;

文档评论(0)

1亿VIP精品文档

相关文档