Chinaunix首页 | 论坛 | 博客
  • 博客访问: 184494
  • 博文数量: 28
  • 博客积分: 648
  • 博客等级: 上士
  • 技术积分: 260
  • 用 户 组: 普通用户
  • 注册时间: 2010-12-17 05:33
文章分类

全部博文(28)

文章存档

2012年(1)

2011年(27)

分类: C/C++

2011-08-25 08:44:09

本来想添加一个输入是否为数字的判断,没成功,以后再改进!

  1. #include <iostream>

  2. using namespace std;

  3. double f1( double a, double b=1){
  4.     b*=a;
  5.     if(a==1) return b;
  6.     else f1(a-1,b);
  7. }

  8. void f2(int& c){
  9.     double a,b;
  10.     cout << "Enter the number: ";
  11.     cin >> a;
  12.     b=f1(a);
  13.     cout << a << "!= "<< b <<endl;
  14.     cout <<'\n';
  15. }

  16. int main (){
  17.     int a(1);
  18.     while(a==1){
  19.         f2(p);
  20.         cout<<"Do you want to do another calculation? y/n \n";
  21.         char str;
  22.         cin>>str;
  23.         if(str=='Y'||str=='y')continue;
  24.         if(str=='N'||str=='n')a=0;
  25.     }
  26.     return 0;

  27. }
阅读(1599) | 评论(0) | 转发(0) |
0

上一篇:sed 例子

下一篇:dd详解

给主人留下些什么吧!~~