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     //显示1,2,3...10
     8     for(int i=1;i<=10;i++)
     9         cout<<i<<" ";
    10     cout<<endl;
    11 
    12     //显示10,9,8...1
    13     for(int j=10;j>=1;j--)
    14        cout<<j<<" ";
    15     cout<<endl;
    16 
    17     //显示1,3,5...9
    18     for(int k=1;k<=10;k=k+2)
    19        cout<<k<<" ";
    20     cout<<endl;
    21 
    22     //显示ABC...Z   
    23     for(char c='A';c<='Z';c++)
    24        cout<<c;
    25     cout<<endl;
    26 
    27     //显示0,0.1,0.2...1.0
    28     for(float x=0;x<=1.0;x=x+0.1)
    29        cout<<x<<" ";
    30     cout<<endl;
    31 
    32     //显示0,0.1,0.2...1.0
    33     for(float x1=0;x1<=1.0+0.1/2;x1=x1+0.1)
    34        cout<<x1<<" ";
    35     cout<<endl;
    36 
    37     //计算s=1+2+3...+100
    38     int s=0;
    39     for(int n=1;n<=100;n++)
    40         s=s+n;
    41     cout<<"s="<<s<<endl;
    42     return 0;
    43 }
  • 相关阅读:
    angular模板
    Growth: 全栈增长工程师指南
    全栈增长工程师实战
    vue 快速搭建项目 iview
    ng-style
    教程视频链接
    内置对象
    对象—封装、继承
    对象—构造函数
    函数-理论
  • 原文地址:https://www.cnblogs.com/borter/p/9406329.html
Copyright © 2011-2022 走看看