c语言程序设计教程答案海燕,C程序设计(双语版)习题答案.doc

C程序设计(双语版)习题答案

第二章 数据类型 课后习题

1. 下列哪些是合法的变量名?如果合法,你认为它是一个好的助记符(能提醒你它的用途)吗?

a stock_code 合法、好的助记符

b money$ 非法,$为非法字符

c Jan_Sales合法、好的助记符

d X-RAY非法,–为非法字符

e int非法,int为关键字

f xyz合法、不是好的助记符

g 1a非法,变量名必须以字母或下划线打头

h invoice_total合法、好的助记符

i john's_exam_mark非法,’为非法字符

j default非法,default为关键字

2. 请确定下列常量的数据类型:

a 'x'char

b -39int

c 39.99double

d -39.0double

3. 下列哪些是合法的变量定义?

a integer account_code ;非法,无integer类型

b float balance ;合法

c decimal total ;非法,无decimal类型

d int age ; 合法

e double int ; 非法,int为关键字,不能作为变量名

f char c ; 合法

4. 写出下列各小题中的变量定义:

a 整型变量number_of_transactions和age_in_years

int number_of_transactions, age_in_years;

b 单精度浮点型变量total_pay,tax_payment,distance和average

float total_pay, tax_payment, distance, average;

c 字符型变量account_type

char account_type;

d 双精度浮点型变量gross_pay

double gross_pay;

5. 为下列各小题写出最合适的变量定义:

a 班级中的学生人数int number_of_students;

b 平均价格 float average_price;

c 自1900年1月1日以来的天数int days_since_1900;

d 利率百分比 float interest_rate; e 本页中最常出现的字符char most_common_char; f 中国的人口总数(在2010年11月大约为1,339,724,852)int population_of_china;

6. 假定有如下定义:

int i ;

char c ;

下面哪些是合法的C语句?

c 'A' ;合法

i "1" ;非法,字符串不能赋值给整型

i 1 ;合法

c "A" ;非法,”A”为字符串,存储为’A’和’\0’两个字符

c '1';合法

7. 写一个C程序,给第4题中的变量各赋一个值,然后以每行一个变量的形式显示这些变量的值。

#include

int main void int number_of_transactions, age_in_years; float total_pay, tax_payment, distance, average; char account_type; double gross_pay; number_of_transactions 211; age_in_years 66; total_pay 3128.0f; tax_payment 214.5f; distance 2431.5f; average 83.5f; account_type 'c'; gross_pay 9313.5; printf "%d\n%d\n%.1f\n%.1f\n%.1f\n%.1f\n%c\n%.1f", number_of_transactions, age_in_years, total_pay, tax_payment, distance, average, account_type, gross_pay ; return 0; 8. 写一个C程序显示如下信息:

*************** * Hello World *

***************

#include

int main void printf "***************\n" ; printf "* Hello World *\n" ;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值