c_primer——第五版——第5章习题解析

复习题


5.5:

c_primer——第五版——第5章习题解析_第1张图片其中第一个printf语句等同于  printf("%s! C is cool!\n","%s! C is cool!\n")


练习题


5.1:

#include
#define HOUR 60
int main()
{
	int minute = 1;
	int hour;
	while(minute)
	{
		printf("请输入分钟表示的时间:");
		scanf("%d",&minute);
		printf("分钟表示的时间为:%d\n",minute);

		hour = minute/HOUR;
		printf("小时分钟表示为:%d小时%d分钟\n",hour,minute-hour*HOUR);
	}
	getchar();
	return 0;
}

5.2:

#include
#define HOUR 60
int main()
{
	int m;
	printf("请输入一个整数:");
	scanf("%d",&m);

	for(int i = m;i<=m+10;i++)
		printf("%d ",i);

	printf("\n");
	int j = m;
	while(j<=m+10)
	{
		printf("%d ",j);
		j++;
	}
	printf("\n");


	int jj = m;
	while(jj<=m+10)
		printf("%d\t",jj++);
		

	getchar();
	getchar();
	return 0;
}

5.3:

#include
#define WEEK 7
int main()
{
	int m,week;
	printf("请输入天数:");
	scanf("%d",&m);
	week = m/WEEK;
	printf("%d days are %d weeks, %d days\n",m,week,m - week*WEEK);

	getchar();
	getchar();
	return 0;
}

5.4:同第一题类似

5.5:很简单啊,略

加入:

        int day ;
        printf("请输入总天数:");
	scanf("%d",&day);

5.6:

#include
int main()
{
	int count = 0;
	int sum = 0;
	while(count++<20)
	{
		sum = sum + count*count;
	}
	printf("sum = %d\n",sum);
	getchar();
	return 0;
}

5.7:

#include
double lifang(double x)
{
	return x*x*x;

}
int main()
{
	double m ;
	printf("请输入一个数:");
	scanf("%lf",&m);
	printf("value = %lf\n",lifang(m));

	getchar();
	getchar();
	return 0;
}

5.8:

#include
int main()
{
	int sybol1 = 0;
	int x = 1;
	printf("请输入第一个数:");
	scanf("%d",&sybol1);

	while(x)
	{
		printf("请输入第二个数:");
	    scanf("%d",&x);
		printf("取模结果为:%d\n",x%sybol1);
	}
	getchar();
	getchar();
	return 0;
}

5.9:

#include

void Temperatures(double tempt)
{
	double sheshi;
	double kaishi;
	printf("华氏温度为:%2lf\n",tempt);
	printf("华氏温度为:%.2lf\n",tempt);

	sheshi = 5.0/9.0*(tempt - 32);
	printf("摄氏温度为:%2lf\n",sheshi);
	printf("摄氏温度为:%.2lf\n",sheshi);

	kaishi = sheshi + 273.16;
	printf("开氏温度为:%2lf\n",kaishi);
	printf("开氏温度为:%.2lf\n",kaishi);
}
int main()
{
	double sybol1 = 0;

	printf("请输入华氏温度:");
	scanf("%lf",&sybol1);
	Temperatures(sybol1);
	
	getchar();
	getchar();
	return 0;
}

 

 

 

 

 

 

你可能感兴趣的:(c)