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 //函数原型语句
     6 int  abs(int x);
     7 long abs(long x);
     8 float abs(float x);
     9 
    10 //main()函数的定义
    11 int main(int argc, char** argv) {
    12     //声明变量
    13     int i1=32767,i2=-32767;
    14     long l1=456789,l2=-456789;
    15     float x1=1.1234,x2=-1.1234;
    16    
    17     //直接在cout输出中调用函数
    18     cout<<abs(i1)<<","<<abs(i2)<<endl;
    19     cout<<abs(l1)<<","<<abs(l2)<<endl;
    20     cout<<abs(x1)<<","<<abs(x2)<<endl;
    21     return 0;
    22 }
    23 
    24 
    25 //定义int型的abs()函数
    26 int abs(int x) {
    27     if (x<0)
    28        return(-x);
    29     else
    30        return(x);
    31 }
    32 
    33 //定义long型的abs()函数 
    34 long abs(long x) {
    35     if (x<0)
    36        return(-x);
    37     else
    38         return(x);
    39 }
    40 
    41 //定义float型 abs函数
    42 float abs(float x) {
    43     if (x<0.0)
    44        return(-x);
    45     else
    46        return(x);
    47 }
  • 相关阅读:
    正则表达式之re模块
    collections模块
    openpyxl模块
    hashlib模块
    random模块
    os模块
    sys模块
    nodeType
    数据类型转换
    添加删除
  • 原文地址:https://www.cnblogs.com/borter/p/9412947.html
Copyright © 2011-2022 走看看