zoukankan      html  css  js  c++  java
  • 一行代码只做一件事情

    一行代码只做一件事情,如只定义一个变量,或只写一条语句。这样 的代码容易阅读,并且方便于写注释。

     1 #include <iostream>
     2 
     3 /* run this program using the console pauser or add your own getch, system("pause") or input loop */
     4 using namespace std;
     5 int main(int argc, char** argv) {
     6         //函数原型声明
     7     int fact(int x);
     8     int n,sn;
     9 
    10     //依次从键盘上输入3个正整型数据计算它们的阶乘
    11     for (int i=1;i<=3;i++)
    12     {
    13         cout<<i<<"   n=";
    14         cin>>n;
    15         sn=fact(n);
    16         cout<<n<<"!="<<sn<<endl;
    17     }
    18     return 0;
    19 }
    20 
    21 
    22 //以下是采用递归方法定义的fact()函数
    23 int fact(int x)
    24 {
    25    if (x==0) return(1);
    26       return(x*fact(x-1));  //此处又调用了它自身
    27 }
  • 相关阅读:
    缓存Cache
    RDD的行动操作
    redis数据库的配置
    requests的封装(user-agent,proxies)
    phantjs
    python多线程
    etree-xpath
    Flask
    Flask
    Flask
  • 原文地址:https://www.cnblogs.com/borter/p/9413065.html
Copyright © 2011-2022 走看看