vc++ 6.0 的%u 与 %ul

刚刚在做实验,书本里面有代码如下:
ContractedBlock.gif ExpandedBlockStart.gif View Code
 
    
1 #include " stdio.h "
2
3 unsigned long lcm(unsigned a,unsigned b);
4 unsigned long lcm3(unsigned a,unsigned b,unsigned c);
5
6 unsigned long lcm(unsigned a,unsigned b)
7 {
8 unsigned long multiple,c = 0 ;
9
10 multiple = a * b;
11 while (a % b != 0 )
12 {
13 c = a % b;
14 a = b;
15 b = c;
16 }
17
18 return multiple / b;
19 }
20
21 unsigned long lcm3(unsigned a,unsigned b,unsigned c)
22 {
23 return lcm(lcm(a,b),c);
24 }
25
26
27 int main()
28 {
29 unsigned long x,y,z;
30 printf( " please input three number: " );
31 scanf( " %ul %ul %ul " , & x, & y, & z);
32 printf( " %ul %ul %ul " ,x,y,z);
33 printf( " the result is %ul " ,lcm3(x,y,z));
34 return 0 ;
35 }
基本思路是说想求三个数的公约数,但在vc++ 6.0 里结果却是错的...
后来不断地排除,发现是在vc++ 6.0 里用不了 %ul,必须改成 %u...
修改后的代码如下:
ContractedBlock.gif ExpandedBlockStart.gif View Code
 
    
1 #include " stdio.h "
2
3 unsigned long lcm(unsigned a,unsigned b);
4 unsigned long lcm3(unsigned a,unsigned b,unsigned c);
5
6 unsigned long lcm(unsigned a,unsigned b)
7 {
8 unsigned long multiple,c = 0 ;
9
10 multiple = a * b;
11 while (a % b != 0 )
12 {
13 c = a % b;
14 a = b;
15 b = c;
16 }
17
18 return multiple / b;
19 }
20
21 unsigned long lcm3(unsigned a,unsigned b,unsigned c)
22 {
23 return lcm(lcm(a,b),c);
24 }
25
26
27   int main()
28 {
29 unsigned long x,y,z;
30 printf( " please input three number: " );
31 scanf( " %u %u %u " , & x, & y, & z);
32 printf( " %u %u %u " ,x,y,z);
33 printf( " the result is %u " ,lcm3(x,y,z));
34 return 0 ;
35 }

转载于:https://www.cnblogs.com/laizhd/archive/2011/04/03/2004492.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值