在每个类声明之后、每个函数定义结束之后都要加空行。

在每个类声明之后、每个函数定义结束之后都要加空行。

 

 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 }

 

转载于:https://www.cnblogs.com/borter/p/9412947.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值