• vc++ 6.0 的%u 与 %ul


    刚刚在做实验,书本里面有代码如下:
    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...
    修改后的代码如下:
    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 }
  • 相关阅读:
    pytest-html的更多功能
    pytest使用allure测试报告
    airtest+pytest实战教程02-APP页面元素获取
    airtest+pytest实战教程01-环境配置
    python发送邮件
    python获取文件名
    python生成GIF
    Selenium+Unittest自动化测试框架实战
    xpath定位和css定位
    Lucas(卢卡斯)定理模板&&例题解析([SHOI2015]超能粒子炮·改)
  • 原文地址:https://www.cnblogs.com/laizhd/p/2004492.html
Copyright © 2020-2023  润新知