c语言程序设计第三章题解

都是自己写的,自己测试过了,难免和学习知道上有些不同,敬请谅解,但是程序绝对原创,第三章比较简单。

3.1

//if the rate of GDP's growth in our country is 9%,
//please write a program and output how much the GDP grows after ten year
#include <stdio.h>
#include <math.h>
int main()
{
	float rate,percent,year,i;
	rate=0.09;
	year=10;
	percent=pow(1+rate,year);//using math function
	printf("The GDP has grown %f compare to 10 years ago.\n",percent);
	
	percent=1;
	for(i=0;i<10;i++)//using circulation
	{
		percent*=(1+rate);
	}
	printf("The GDP has grown %f compare to 10 years ago.\n",percent);
	
	return 0;//dd
}

3.2

//dispoit $1000 for five years has five ways,
//please compare the 5 ways.
#include <stdio.h>
#include <math.h>
int main()
{
	float t0,t1,t2,t3,t4,r0,r1,r2,r3,r4;
	int n=5;
	t0=t1=t2=t3=t4=1000;
	r0=0.0414;//1 year deposit rate
	r1=0.0468;//2 year deposit rate
	r2=0.054;//3 year deposit rate
	r3=0.0585;//5 year deposit rate
	r4=0.0072;//current deposit rate

    t0*=(1+n*r3);//5 years one time
    
	t1*=(1+2*r1);
	t1*=(1+3*r2);//deposit 2 years first then 3 years
	
	t2*=(1+3*r2);
	t2*=(1+2*r1);//deposit 3 years first then 2 years
	
	t3*=pow(1+r3,n);//one year for 5 times
	
	t4*=pow(1+r4/4,4*n);//current deposit
	
	printf("You will have $%.2f if you take the first method.\n",t0);
	printf("You will have $%.2f if you take the second method.\n",t1);
	printf("You will have $%.2f if you take the third method.\n",t2);
	printf("You will have $%.2f if you take the forth method.\n",t3);
	printf("You will have $%.2f if you take the fifth method.\n",t4);
	
	return 0;//dd
}

3.3

//There is a loan,calculate when it can be payed off
#include <stdio.h>
#include <math.h>
int main()
{
	float m,r=0.01;
	float loan=300000,pmonth=6000;
    m=log10((pmonth)/(pmonth-loan*r))/log10(1+r);
	printf("The money will be payed off in %.1f years.\n",m);
	return 0;//dd
}

3.5

//how to let a=3,b=7,x=8.5,y=71.82,c1='A',c2='a';
#include <stdio.h>
int main()
{
	int a,b;
	float x,y;
	char c1,c2;
	scanf("a=%d b=%d",&a,&b);
	scanf("%f %e",&x,&y);
	scanf("%c%c",&c1,&c2);
	
	
	printf("a=%d b=%d\n",a,b);
	printf("x=%f y=%e\n",x,y);
	printf("c1=%c c2=%c\n",c1,c2);
	
	return 0;//dd
}



3.6
//translate the code China->Glmre,ASCII+4
#include <stdio.h>
int main()
{
	char c1='C',c2='h',c3='i',c4='n',c5='a';//using char
	int c6='C',c7='h',c8='i',c9='n',c10='a';//using int
	c1+=4;
	c2+=4;
	c3+=4;
	c4+=4;
	c5+=4;
	printf("China: %c%c%c%c%c\n",c1,c2,c3,c4,c5);
	

	c6+=4;
	c7+=4;
	c8+=4;
	c9+=4;
	c10+=4;
	printf("China: %c%c%c%c%c\n",c6,c7,c8,c9,c10);
	
	return 0;//dd
}

3.7

//enter r and h,output the circumference,area of the circle,the superficial area,the volume of the ball;
//the volume of column
#include <stdio.h>
int main()
{
	float r,h,cc,ac,ab,vb,vc,PI=3.141;
	printf("Please enter the r and h: (r,h)\n");
	scanf("%f,%f",&r,&h);
	
	cc=2*PI*r;
	ac=PI*r*r;
	ab=4*PI*r*r;
	vb=4.0/3*PI*r*r*r;
	vc=PI*r*r*h;
	
	printf("The circum of the circle is: %.2f\n",cc);
	printf("The area of the circle is: %.2f\n",ac);
	printf("The superfical area of the ball is: %.2f\n",ab);
	printf("The volume of the ball is: %.2f\n",vb);
	printf("The volume of column is: %.2f\n",vc);
	
	return 0;//dd
}
这些程序都很简单,只需要写的时候认真点就行了,错误都是些无法容忍的小细节,在以后完全应该避免。希望以后继续努力。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值