#include <stdio.h>
#include <math.h>
#include <iostream>
using namespace std;
int main(){
double n = 10;
double r = 0.09;
double p;
p = pow(1+r,n);
printf("Ten years has increase %f%",p);
return 1;
}
(1) 一次存5年期
(2)先存2年,到期后将本息再存3年期
(3)先存3年,到期后将本息再存2年期
(4)存1年期,到期后将本息再存1年,连续存5次
(5)存活期存款,活期利息每季度结算一次
(1)
#include <stdio.h>
#include <iostream>
using namespace std;
int main(){
int b = 1000;
int n = 5;
double r = 0.0585;
printf("After 5 years u can get %f",(b*(1+n*r)));
return 1;
}
(2)
#include <stdio.h>
#include <iostream>
using namespace std;
int main(){
int b = 1000;
int n1 = 2;
int n2 = 3;
double res1;
double r1 = 0.0468;
double r2 = 0.054;
res1 = b * (1+n1*r1);
printf("After 5 years u can get %f",(res1*(1+n2*r2)));
return 1;
}
(3)
#include <stdio.h>
#include <iostream>
using namespace std;
int main(){
int b = 1000;
int n1 = 3;
int n2 = 2;
double res1;
double r1 = 0.054;
double r2 = 0.0468;
res1 = b * (1+n1*r1);
printf("After 5 years u can get %f",(res1*(1+n2*r2)));
return 1;
}
(4)
#include <stdio.h>
#include <math.h>
#include <iostream>
using namespace std;
int main(){
int b = 1000;
int n = 5;
double r = 0.0414;
printf("After 5 years u can get %f",(b*pow(1+r,n));
return 1;
}
(5)
#include <stdio.h>
#include <math.h>
#include <iostream>
using namespace std;
int main(){
int b = 1000;
int n = 5;
double r = 0.0072;
printf("After 5 years u can get %f",(b*pow(1+r/4,4*n));
return 1;
}
设d为300000元,p为6000元,r为1%,求得的月份去小数点后一位,对第二位按四舍五入处理。
#include <stdio.h>
#include <math.h>
#include <iostream>
using namespace std;
int main(){
double m;
int d = 300000;
int p = 6000;
double r = 0.01;
m = log(p/(p-d/r))/log(1+r);
m = (int)(m*10+0.5)/10.0;
printf("U need to pay %f month",m);
return 1;
}
#include <stdio.h>
int main(){
char c1,c2;
c1 = 97;
c2 = 98;
printf("c1 = %c , c2 = %c\n",c1,c2);
printf("c1 = %d , c2 = %d\n",c1,c2);
return 0;
}
(1)运行时会输出什么信息,为什么?
答:会输出
c1 = a , c2 = b
c1 = 97 , c2 = 98
因为ascii 97对应的是a,98对应的是b
(2) 如果将程序4,5行改为
c1=197;
c2=198;
运行时会输出什么信息,为什么?
答:会输出
%c的情况下会因系统不同出现不同的结果
%d的情况下c1 = -59 , c2 = -58
因为ascii的表示范围是到0-127,超出范围后会用补码进行表示
(3)如果将程序第三行改为
int c1,c2;
答:会输出
%c的情况下会因系统不同出现不同的结果
%d的情况下会输出c1 = 97 , c2 = 98
#include <stdio.h>
int main(){
int a,b;
float x,y;
char c1,c2;
scanf("a=%db=%d",&a,&b);
scanf("%f%f",&x,&y);
scanf("%c%c",&c1,&c2);
return 0;
}
输入为:
3,7
8.5,71.82
A,a
#include <stdio.h>
#include <iostream>
using namespace std;
int main(){
char c1,c2,c3,c4,c5;
c1 = C;
c2 = h;
c3 = i;
c4 = n;
c5 = a;
c1 += 4;
c2 += 4;
c3 += 4;
c4 += 4;
c5 += 4;
putchar(c1);
putchar(c2);
putcahr(c3);
putchar(c4);
putchar(c5);
printf("%c%c%c%c%c",c1,c2,c3,c4,c5);
return 1;
}
#include <stdio.h>
#include <iostream>
using namespace std;
int main(){
double r;
int h;
scanf("%f%d",&r,&h);
double c = (int)(3.14*r*2)*100/100;
printf("圆周长为:%f",c);
double s = (int)(3.14*r*r)*100/100;
printf("圆面积为:%f",s);
double s1 = (int)(4*3.14*r*r)*100/100;
printf("圆球表面积为:%f",s1);
double s2= (int)(4/3*3.14*r*r*r)*100/100;
printf("圆球体积为:%f",s2);
double s3 = (int)(s*h)*100/100;
printf("圆柱体积为:%f",s3);
return 1;
}
用getchar函数读入两个字符给c1和c2,然后分别用putchar函数和printf函数输出这两个字符。
(1)变量c1和c2应定义为字符型还是整形,或二者皆可
(2)要求输出c1和c2值的ascii应如何处理?用putchar还是printf
(3)整形变量和字符变量是否在任何情况下都可以互相替代
char c1,c2
与
int c1,c2;
是否无条件等价
#include <stdio.h>
#include <iostream>
using namespace std;
int main(){
char c1,c2;
c1 = getchar();
c2 = getchar();
printf("putchar(),c1,c2:");
putchar(c1);
printf(",");
putchar(c2);
printf("/n");
printf("printf : c1 = %c,c2 = %c",c1,c2);
}
(1)将c1,c2定义为字符型和整形均可
(2)需要使用printf函数进行输出,将其中的%c换为%d
(3)整形变量所占字符个数为4个,短整型为2个,长整型为8个;字符型变量所占字符个数为1个,故整型变量在可输出字符的范围内(ASCII码为0到127之间的字符)是可以与字符型数据互相转换的。如果整数在此范围外,不能代替。
第8题引用:链接: https://blog.csdn.net/yanxiaolx/article/details/51531653.