跪求《C语言程序设计》课本习题答案!!!

Python011

跪求《C语言程序设计》课本习题答案!!!,第1张

习题1参考答案

一、选择题 1. A 2. D

二、填空题

1. BASIC、FORTRAN、AL_GOL60和COBOL 2. 8

3. 关键字

4. 编辑、编译、链接和运行

三、简答题 1.答:

(1)C语言具有结构化的控制语句。C语言提供了结构化程序所必需的基本控制语句,实现了对逻辑流的有效控制。

(2)C语言具有丰富的数据结构类型。C语言除提供整型、实型、字符型等基本数据类型外,还提供了用基本数据类型构造出的各种复杂的数据结构,如数组、结构、联合等。C语言还提供了与地址密切相关的指针类型。此外,用户还可以根据需要自定义数据类型。 (3)C语言具有丰富的运算符。C语言提供了多达34种运算符,丰富的数据类型与丰富的运算符相结合,使C语言的表达力更具灵活性,同时也提高了执行效率。

(4)C语言简洁、紧凑,使用方便、灵活,程序书写自由,有9种控制语句。

(5)C语言既具有高级语言的功能,又具有低级语言的许多功能,通常被称为中级计算机语言。它既是成功的系统描述语言,又是通用的程序设计语言。 (6)C语言与汇编语言相比,可移植性好。

(7)功能强大。C语言具有低级语言的一些功能,所以,生成目标代码质量高,程序执行效率高。现在许多系统软件都用C语言来描述,可以大大提高了编程效率。

2.答:运行一个C语言程序,一般需要经过如下几个步骤:①上机输入并编辑源程序;②编译源程序;③与库函数连接;④生成可执行目标程序;⑤运行目标程序。 3.答:

(1)操作系统的设计与实现。C语言是一种应用非常广泛的结构化高级程序设计语言,既适合编写应用软件,又适合编写系统软件。

以前上课的时候不想做,现在很想补下,很后悔没好好学习呢~希望楼主好好努力

第4道1):

#include<stdio.h>

void main(void)

{

int i,j,a[80],max,max_i

printf("please input 10 num!\n")

for(i=0i<10i++)

scanf("%d",&a[i])

printf("the 10 num is:\n")

for(i=0i<10i++)

printf("%d\t",a[i])

for(max=a[0],i=0i<10i++)

{

if(max<a[i])

{

max=a[i]

max_i=i

}

}

printf("the max num is:a[%d]=%d\n",max_i+1,max)

getch()

}

2)道:

#include<stdio.h>

void main(void)

{

int a[3][2],i,j,sum[3]

for(i=0i<3i++)

{

printf("please input the score of the student %d\n",i+1)

scanf("%d%d",&a[i][0],&a[i][1])

sum[i]=a[i][0]+a[i][1]

}

for(i=0i<3i++)

{

printf("the score of the student %d is:%d\t%d\n",i+1,a[i][0],a[i][1])

printf("the sum score of the student %d is:%d\n",i+1,sum[i])

}

getch()

}

3)道:

#include<stdio.h>

#include<string.h>

main()

{

int i

char string1[80],string2[80]

printf("please input the string 1\n")

scanf("%s",string1)

printf("please input the string 2\n")

scanf("%s",string2)

if(strcmp(string1,string2)==0)

printf("the 2 string is the same\n")

else

printf("the 2 string is different\n")

getch()

}

第5道:

#include<stdio.h>

main()

{

float c,f

printf("please input the F\n")

scanf("%f",&f)

c=(f-32)*5/9

printf("the convert result is:%.2f\n",c)

getch()

}

小问:

float convert(float a)

{

float b

b=(a-32)*5/9

return b

}

main()

{

float c,f

printf("please input the F\n")

scanf("%f",&f)

c=convert(f)

printf("the convert result is %.2f\n",c)

getch()

}

第6道:

#include<stdio.h>

main()

{

int x,y,*p1,*p2

printf("please input the 2 nums\n")

scanf("%d%d",&x,&y)

swap1(x,y)

printf("the swap1 result is:%d\t%d\n",x,y)

p1=&x

p2=&y

swap2(p1,p2)

printf("the swap2 result is:%d\t%d\n",*p1,*p2)

getch()

}

swap1(int x,int y)

{

int temp

temp=x

x=y

y=temp

}

swap2(int *p1,int *p2)

{

int temp

temp=*p1

*p1=*p2

*p2=temp

}

6.2)

#include <stdio.h>

void main()

{

char s[80]/*定义一个数组*/

char c

printf("which style you want to:\n")/*是\不是|*/

printf("capital ( c ) or uncapital(a):")

c=getchar()

if(c=='c')/*是==不是=*/

strcpy(s,"COMPUTER")

else

strcpy(s,"computer")

puts(s)

getch()

}

第七道

struct student

{

char num[8]

char name[80]

float score

}stu[4]

main()

{

int i,max,max_i

for(i=0i<4i++)

{

printf("input the num of student %d\n",i+1)

scanf("%s",&stu[i].num)

printf("input the name of student %d\n",i+1)

scanf("%s",&stu[i].name)

printf("input the score of student %d\n",i+1)

scanf("%f",&stu[i].score)

}

for(max=stu[0].score,i=0i<4i++)

{

if(max<stu[i].score)

{

max=stu[i].score

max_i=i

}

}

printf("the highest score student is student%d\n",max_i+1)

printf("%s\t%s\t%.2f\n",stu[max_i].num,stu[max_i].name,stu[max_i].score)

getch()

}

第八道:

Java的行不,C++的不记得了。

public class Circle

{

private static double PI=3.14

private double radius

public Circle(double radius)

{

this.radius=radius

}

public double Area()

{

return PI*radius*radius

}

public double Perimeter()

{

return 2*PI*radius

}

}

第一题

#include<stdio.h>

void main()

{ int i

int count=1

printf("请输入数据:")

scanf("%d",&i)

printf("逆序输出结果为:")

while(i/10)

{printf("%d ",i%10)

count++

i=i/10}

printf("%d\n",i%10)

printf("它是%d位数\n",count)

}

第二题

#include<stdio.h>

int fact(int n)

{

int i

int f=1

for(i=1i<=ni++)

f*=i

return f

}

float sum(int n)

{

float sum1=0

int i

for(i=1i<=ni++)

sum1+=1.0/fact(i)

return sum1

}

void main()

{ int i

float total

printf("请输入数据:")

scanf("%d",&i)

total=sum(i)

printf("结果为:")

printf("%.5f ",total)

}

上面两个程序已经上机通过了。。。