《C Primer Plus》第2章 C语言概述

C语言概述

2.1

/first.c
#include <stdio.h>
int main(void)
{
    int num;
    num = 1;
    printf("I am a simple");
    printf("computer.
");
    printf("My favorite number is %d because it is first.
", num);

    getchar();
    return 0;
}

2.2

//fathm_ft.c--把2英寻转化为英尺
#include <stdio.h>
int main(void)
{
    int feet, fathoms;

    fathoms = 2;
    feet = 6 * fathoms;
    printf("There are %d feet in %d fathoms!
", feet, fathoms);
    printf("Yes, I said %d feet!
", 6 * fathoms);

    getchar();
    return 0;
}

2.3

/* two_func.c--一个文件中包含两个函数*/
#include <stdio.h>
void butler(void);
int main(void)
{
    printf("I will summon the butler function.
");
    butler();
    printf("Yes. Bring me some tea and writeable DVDs.
");

    getchar();
    return 0;
}
void butler(void)
{
    printf("You rang, sir?.
");
}

2.4

/*nogood.c--有错误的程序*/
#include <stdio.h>
int main(void)
{
    int n; int n2; int n3;

    /*该程序有多处错误*/
    n = 3;
    n2 = n*n;
    n3 = n2*n;
    printf("n = %d, n squared = %d, n cubed = %d
", n, n2, n3);

    getchar();
    return 0;
}

2.5略

原文地址:https://www.cnblogs.com/Math-Nav/p/13550971.html