目录
4.Indiana Sloth编写了下面的程序,并征求你的意见。请帮助他评定。
5.假设下面的4个例子都是完整程序中的一部分,它们都输出什么结果?
6.在main、int、function、char、=中,哪些是C语言的关键字?
7.如何以下面的格式输出变量words和lines的值(这里,3020和350代表两个变量的值)? There were 3020 words and 350 lines.
3.编写一个程序把你的年龄转换成天数,并显示这两个值。这里不用考虑闰年的问题。
6.编写一个程序,创建一个整型变量toes,并将toes设置为10。程序中还要计算toes的两倍和toes的平方。该程序应打印3个值,并分别描述以示区分
7.许多研究表明,微笑益处多多。编写一个程序,生成以下格式的输出:
复习题
1.C语言的基本模块是什么?
函数
2.什么是语法错误?写出一个英语例子和C语言例子。
3.什么是语义错误?写出一个英语例子和C语言例子。
4.Indiana Sloth编写了下面的程序,并征求你的意见。请帮助他评定。
include studio.h
int main{void} /* 该程序打印一年有多少周 /*
( int s
s := 56;
print(There are s weeks in a year.);
return 0;
行一:include→#include studio.h→《stdio.h》
行二:{}→()
行三:(→{ s→s;
行四::=→=
行五:There are s weeks in a year.→"There are %d weeks in a year.", s
行六:;→;}
5.假设下面的4个例子都是完整程序中的一部分,它们都输出什么结果?
a. printf("Baa Baa Black Sheep."); printf("Have you any wool?\n");
b. printf("Begone!\nO creature of lard!\n");
c. printf("What?\nNo/nfish?\n");
d. int num; num = 2; printf("%d + %d = %d", num, num, num + num);
a.
Baa Baa Black Sheep.Have you any wool?
b.
Begone!
O creature of lard!
c.
What?
No/nfish?
d.
2 + 2 = 4
6.在main、int、function、char、=中,哪些是C语言的关键字?
关键字是:
int char
【注意区分关键字和其它】
7.如何以下面的格式输出变量words和lines的值(这里,3020和350代表两个变量的值)? There were 3020 words and 350 lines.
printf("There were %d words and %d lines", words, lines);
8.考虑下面的程序:
#include <stdio.h>
int main(void)
{
int a, b;
a = 5; b = 2; /* 第7行 */
b = a; /* 第8行 */
a = b; /* 第9行 */
printf("%d %d\n", b, a);
return 0;
}
第7行:a = 5, b = 2
第8行:b = 5, a = 5
第9行:a = 5, b = 5
9.考虑下面的程序:
#include <stdio.h>
int main(void)
{
int x, y;
x = 10;
y = 5; /* 第7行 */
y = x + y; /*第8行*/
x = x*y; /*第9行*/
printf("%d %d\n", x, y);
return 0;
}
第七行:x = 10, y = 5
第八行:x = 10, y = 15
第九行:x = 150, y = 15