zoukankan      html  css  js  c++  java
  • C/C++:printf的用法

    #include <stdio.h>
    
    int main()
    {
        printf("hello world!
    ");
    
        //显示整数
        printf("a:%d
    ", 33);
        printf("a:%d, b:%d
    ", 32,34);
    
        //指定整数位数
        int a = 3;
        int b = 33;
        int c = 333;
        printf("number:%3d
    ", a);
        printf("number:%3d
    ", b);
        printf("number:%3d
    ", c);
    
        //用int型表示整数
        printf("a:%d,b:%d
    ", a, b);
    
        //显示小数
        printf("x=%f
    ", 12.35);
        printf("x=%f,y=%f
    ", 12.35, 90.01);
    
        //用double表示小数
        double x = 123.456;
        double y = 99.87;
        printf("x=%f,y=%f
    ", x, y);
    
        //指定小数点后的位数
        //指定显示小数点后2位,四舍五入使用%.2f
        printf("x is %.2f
    ", x);
    
        //例1
        //求123和456的乘积
        printf("result:%d
    ", 123 * 456);
        //或者
        int a1 = 123;
        printf("result:%d
    ", a1 * 456);
    
        //例2
        //求123.345的平方,输出结果,保留4位小数
        double a2 = 12.345;
        printf("结果:%.4f
    ", a2 * a2);
    
    
    
        getchar();
        return 0;
    }

  • 相关阅读:
    PHP输出日志,json美化
    php获取项目路径
    16进制颜色,正则
    doctrine/instantiator
    cn.archive.ubuntu.com 慢的问题
    yzalis/identicon 像素头像
    Shell 判断进程是否存在
    shell 2>&1
    shell 判断是否继续
    shell
  • 原文地址:https://www.cnblogs.com/nxopen2018/p/13882051.html
Copyright © 2011-2022 走看看