【c语言】c程序设计--谭浩强--(第三章)--2

// 假如我国国民生产总值的年增长率为9%,计算10年后我国国民生产总值与现在相比增长多少百分比
// p = ( 1 + r )^n   r--年增长率  n--年数  p--与现在相比的倍数

#include <stdio.h>
#include <math.h>

int main()
{
	double r = 0.09;
	double p;
	int n = 10;
	p = pow( ( 1 + r ) , n );
	printf("10年后增长了 %f 倍\n",p);
	return 0;
}

// 存款利息的计算。有1000元,想存5年,可按以下5种办法存:
// 1、一次存5年期。
// 2、先存2年期,到期后将本息再存3年期。
// 3、先存3年期,到期后将本息再存2年期。
// 4、存1年期,到期后将本息再存1年期,连续存5次。
// 5、存活期存款。活期利息每一季度结算一次。
// 1年定期利息:4.14%;
// 2年定期利息:4.68%;
// 3年定期利息:5.4%;
// 5年定期利息:5.85%;
// 活期存款利息:0.72%;(活期存款每一季度结算一次利息)
// r--年利率  n--存款年数
// 1年本息和:p = 1000*(1+r);
// n年期本息和:p = 1000*(1+n*r);
// 存n次1年的本息和:p = 1000*(1+r)^n;
// 活期存款本息和:p = 1000*(1+r/4)^4n--一个季度的本息和

#include <stdio.h>
#include <math.h>

int main()
{
	double p1,p2,p3,p4,p5;
	double p0 = 1000.0;
	double r1 = 0.0414;
	double r2 = 0.0468;
	double r3 = 0.054;
	double r4 = 0.0585;
	double huo = 0.0072;
	p1 = p0 * ( 1 + 5 * r4 );
	p2 = ( p0 * ( 1 + 2 * r2 ) ) * ( 1 + 3 * r3 );
	p3 = ( p0 * ( 1 + 3 * r3 ) ) * ( 1 + 2 * r2 );
	p4 = p0 * pow( ( 1 + r1 ) , 5 );
	p5 = p0 * pow( ( 1 + huo / 4 ),20 );
	printf("一次存5年期:%f\n",p1);
	printf("先存2年期,到期后将本息再存3年期:%f\n",p2);
	printf("先存3年期,到期后将本息再存2年期:%f\n",p3);
	printf("存1年期,到期后将本息再存1年期,连续存5次:%f\n",p4);
	printf("存活期存款。活期利息每一季度结算一次:%f\n",p5);

	return 0;
}

// 购房从银行贷了一笔款d,准本每月还款额为p,月利率为r,计算多少月能还清。
// d = 300000  p = 6000  r = 0.01  对求得的月份取小数点后一位,第二位四舍五入
// m = log( p/(p-d*r))/log(1+r)

#include <stdio.h>
#include <math.h>

int main()
{
	float d = 300000.0;
	float p = 6000.0;
	float r = 0.01;
	float m;
	m = log( p / ( p - d * r ) ) / log ( 1 + r );
	printf("需要 %3.1f 个月还清\n",m);

	return 0;
}

// 将“China”译成密码,密码规律:用原来字母后边第4个字母代替原来的字母。
// 要求:先赋初值,然后分别用putchar和printf输出

#include <stdio.h>

int main()
{
	char c1 = 'C';
	char c2 = 'h';
	char c3 = 'i';
	char c4 = 'n';
	char c5 = 'a';
	c1 = c1 + 4;
	c2 = c2 + 4;
	c3 = c3 + 4;
	c4 = c4 + 4;
	c5 = c5 + 4;
	printf("密码是:%c%c%c%c%c\n",c1,c2,c3,c4,c5);
	putchar(c1);
	putchar(c2);
	putchar(c3);
	putchar(c4);
	putchar(c5);
	putchar('\n');

	return 0;
}

// 设圆半径r = 1.5,圆柱高h = 3,求圆周长,圆面积,圆球表面积,圆球体积,圆柱体积
// 要求:用scanf输入数据,取小数点后两位

#include <stdio.h>

int main()
{
	float r,h;
	float c,s,sq,vq,vz;
	float pai = 3.1415926;
	printf("请输入圆半径:");
	scanf("%f",&r);
	printf("请输入圆柱高:");
	scanf("%f",&h);
	c = 2 * pai * r;
	s = pai * r * r;
	sq = 4 * pai * r * r;
	vq = ( 4 / 3 ) * pai * r * r * r;
	vz = s * h;
	printf("圆周长是:%4.2f\n",c);
	printf("圆面积是:%4.2f\n",s);
	printf("圆球表面积是:%4.2f\n",sq);
	printf("圆球体积是:%4.2f\n",vq);
	printf("圆柱体积是:%4.2f\n",vz);

	return 0;
}

时间: 2024-07-31 12:25:46

【c语言】c程序设计--谭浩强--(第三章)--2的相关文章

c++面向对象程序设计 谭浩强 第三章答案

2: #include <iostream> using namespace std; class Date {public: Date(int,int,int); Date(int,int); Date(int); Date(); void display(); private: int month; int day; int year; }; Date::Date(int m,int d,int y):month(m),day(d),year(y) { } Date::Date(int m

【c语言】c程序设计--谭浩强--(第一章)

闲来无事把谭浩强的书里边的题敲了一遍,,纪念一哈,,纯手工 // 在屏幕上输出 This is a c program. #include <stdio.h> int main() { printf("This is a c program.\n"); return 0; } // 求两个整数之和 #include <stdio.h> int main() { int a,b,c; printf("请输入两个整数:\n"); scanf(&q

【c语言】c程序设计--谭浩强--(第二章)--2

// 有两个瓶子a和b,分别盛放醋和酱油,要求将它们互换 #include <stdio.h> int main() { int a,b,c; printf("请输入两个整数:"); scanf("%d%d",&a,&b); c = a; a = b; b = c; printf("交换后的结果是:%d %d\n",a,b); return 0; } // 依次将10个数输入,要求输出其中最大的数 #include &

c++面向对象程序设计 谭浩强 第五章答案

1: #include <iostream> using namespace std; class Student {public: void get_value() {cin>>num>>name>>sex;} void display( ) {cout<<"num: "<<num<<endl; cout<<"name: "<<name<<end

c++面向对象程序设计 谭浩强 第一章答案

c++面向对象程序设计 谭浩强 答案 第一章 第1章  C++?的初步知识 1.请根据你的了解,叙述C++?的特点.C++?对C有哪些发展? [解] 略. 2.一个C++的程序是由哪几部分构成的?其中的每一部分起什么作用? [解] 略. 3.从拿到一个任务到得到最终结果,一般要经过几个步骤? [解] 略. 4.请说明编辑.编译.连接的作用.在编译后得到的目标文件为什么不能直接运行? [解] 编译是以源程序文件为单位进行的,而一个完整的程序可能包含若干个程序文件,在分别对它们编译之后,得到若干个目

c++面向对象程序设计 课后题 答案 谭浩强 第四章

c++面向对象程序设计课后题答案 谭浩强 第四章 1: #include <iostream> using namespace std; class Complex {public: Complex(){real=0;imag=0;} Complex(double r,double i){real=r;imag=i;} double get_real(); double get_imag(); void display(); private: double real; double imag;

c++面向对象程序设计 谭浩强 第二章答案

第二章 类体内定义成员函数 #include <iostream> using namespace std; class Time { public: void set_time(); void show_time(); private:                    //成员改为公用的 int hour; int minute; int sec; }; void Time::set_time()          //在main函数之前定义 { cin>>hour; ci

C语言学习笔记---谭浩强

前段时间有机会去面试了一次,真是备受“打击”(其实是启发),总的来说就是让我意识到了学习工具和学习技术的区别.所以最近在看一些数据结构和算法,操作系统,python中的并行编程与异步编程等东西.然而数据结构那些本来是在看python下的,但是python实在包装了太多的东西而大多的经典教材都是基于C语言的(自然是这样,C语言能够操作直接访问物理地址,能够进行位(bit)操作的特点就决定了.)所以就决定重新学一遍C语言,先重温下谭浩强老师的书籍记录下要点: 一:语言: 机器语言:计算机直接识别和接

【c语言】c程序设计--谭浩强--(第四章)--1

// 输入两个实数,按代数值由小到大的顺序输出这两个数 #include <stdio.h> int main() { int a,b; printf("请输入两个数:"); scanf("%d%d",&a,&b); if(a > b) printf("由小到大:%d %d\n",b,a); else printf("由小到大:%d %d\n",a,b); return 0; } // 输入3