跳至正文
View Categories

< 1 min read

主要内容 #

输出 hello world!

#include < cstdio >
int main()
{
    printf("hello world!");
    return 0;
}

1. 输出整数 #

输出一个和多个整数

#include < cstdio >
int main()
{
    printf("This is %d",  10);
    printf("It is %d, it is %d",  10, 20);
    printf("They are %d, %d,%d",  10, 20, 30);
    return 0;
}

2. 输出小数 #

输出一个和多个小数

#include < cstdio >
int main()
{
    printf("This is %f",  10.6);
    printf("It is %f, it is %f",  1.0, 2.50);
    printf("They are %f, %f,%f",  10.14, 20.6, 3.06);
    return 0;
}

3. 输出字符 #

输出字符

#include < cstdio >
int main()
{
    printf("This is %c",  65); // 输出 This is A
    return 0;
}

输出字符还有第二种方式

#include < cstdio >
int main()
{
    putchar(66);    // 输出 B
    putchar('B');   // 输出 B

    return 0;
}

4. 输出字符串 #

输出字符串

#include < cstdio >
int main()
{
    char str[] = "World";
    printf("Hello %s", str);
    return 0;
}

5. 小结 #

以上,使用了 %d %f %c %s 作为输出内容的标识。除此之外,还有其他的几种

%u    无符号整数
%lf   double
%e    科学计数法
%%    百分号
%x    16 进制数
%o    8 进制数

习题 #

课后练习