看第一二章容易劝退小白。直接验证代码,然后再看汉字。
#include <stdio.h>
int main(void)
{
int dogs;
printf("How many dogs do you have?\n");
scanf("%d", &dogs);
printf("So you have %d dog(s)!\n", dogs);
return 0;
}
#include <stdio.h>
int main(void)
{
printf("Concrete contains gravel and cement.\n");
return 0;
}
// first.c
#include <stdio.h>
int main(void) /* a simple program */
{
int num; /* define a variable called num */
num = 1; /* assign a value to num */
printf("I am a simple "); /* use the printf() function */
printf("computer.\n");
printf("My favorite number is %d because it is first.\n",num);
return 0;
}
// fathm_ft.c -- converts 2 fathoms to feet
#include <stdio.h>
int main(void)
{
int feet, fathoms;
fathoms = 2;
feet = 6 * fathoms;
printf("There are %d feet in %d fathoms!\n", feet, fathoms);
printf("Yes, I said %d feet!\n", 6 * fathoms);
return 0;
}
//* two_func.c -- a program using two functions in one file */
#include <stdio.h>
void butler(void); /* ANSI/ISO C function prototyping */
int main(void)
{
printf("I will summon the butler function.\n");
butler();
printf("Yes. Bring me some tea and writeable DVDs.\n");
return 0;
}
void butler(void) /* start of function definition */
{
printf("You rang, sir?\n");
}
/* nogood.c -- a program with errors */
#include <stdio.h>
int main(void)
(
int n, int n2, int n3;
/* this program has several errors
n = 5;
n2 = n * n;
n3 = n2 * n2;
printf("n = %d, n squared = %d, n cubed = %d\n", n, n2, n3)
return 0;
)
/* nogood.c -- a program with errors */
#include <stdio.h>
int main(void)
{
int n; int n2; int n3;
/* this program has several errors */
n = 5;
n2 = n * n;
n3 = n * n2;
printf("n = %d, n squared = %d, n cubed = %d\n", n, n2, n3);
return 0;
}