1 #define _CRT_SECURE_NO_WARNINGS 1
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <math.h>
5 #include <string.h>
6
7
8 //存款利息的计算
9 int main()
10 {
11 int p = 1000;//本金
12 int n = 5;//存款年限
13 //存款利息
14 float r1 = 0.015, r2 = 0.021, r3 = 0.0275, r5 = 0.03, r0 = 0.0035;
15 float p1 = p*(1 + n*r5);//一次存5年
16 float p2 = p*(1 + 2 * r2)*(1 + 3 * r3);//先存2年,再存3年
17 float p3 = p*(1 + 3 * r3)*(1 + 2 * r2);//先存3年,再存2年
18 float p4 = p*pow(1 + r1, n);
19 float p5 = p*pow(1 + r0 / 4, 4 * n);
20 printf("%.2f\n", p1);//第一种方式的本息和
21 printf("%.2f\n", p2);//第二种方式的本息和
22 printf("%.2f\n", p3);//第三种方式的本息和
23 printf("%.2f\n", p4);//第四种方式的本息和
24 printf("%.2f\n", p5);//第五种方式的本息和
25 system("pause");
26 return 0;
27 }
28
29
30 //房贷还款计算
31 int main()
32 {
33 int d = 300000, p = 6000;
34 float r = 0.01;//利率
35 float m = (log(p) - log(p - d*r)) / log(1 + r);
36 float n = log(p / (p - d*r)) / log((1 + r));
37 printf("m=%.1f\n", m);
38 printf("n=%.1f\n", n);
39 system("pause");
40 return 0;
41 }
42
43
44 //改错题
45 int main()
46 {
47 char c1, c2;
48 c1 = 97;
49 c2 = 98;
50 /*c1 = 197;
51 c2 = 198;*/
52 int c1, c2;
53 printf("c1=%c,c2=%c\n", c1, c2);
54 printf("c1=%d,c2=%d\n", c1, c2);
55 system("pause");
56 return 0;
57 }
58
59 //输入数据
60 int main()
61 {
62 int a, b;
63 float x, y;
64 char c1, c2;
65 scanf("a=%db=%d", &a, &b);
66 scanf("%f%e", &x, &y);
67 scanf("%c%c", &c1, &c2);
68 system("pause");
69 return 0;
70 }
71
72 //将China译成密码:用原来字母后4个字符代替原来字符
73 int main()
74 {
75 char c1, c2, c3, c4, c5;
76 c1 = 'C', c2 = 'h', c3 = 'i', c4 = 'n', c5 = 'a';
77 //编码翻译
78 c1 = c1 + 4;//c1+=4;
79 c2 = c2 + 4;//c2+=4;
80 c3 = c3 + 4;//c3+=4;
81 c4 = c4 + 4;//c4+=4;
82 c5 = c5 + 4;//c5+=4;
83 printf("使用putchar函数输出:>");
84 putchar(c1);
85 putchar(c2);
86 putchar(c3);
87 putchar(c4);
88 putchar(c5);
89 printf("\n");
90 printf("使用printf函数输出:>");
91 printf("%c %c %c %c %c\n", c1, c2, c3, c4, c5);
92 system("pause");
93 return 0;
94 }
95 //数组做
96 int mian()
97 {
98 int ch[] = { "China" };
99 int i;
100 for (i = 0; i < ch; i++)
101 {
102 ch[i] += 4;
103 }
104 printf("%c", ch);
105 system("pause");
106 return 0;
107 }
108
109
110 //求圆的周长、圆的面积、圆球表面积、圆球体积、圆柱体积
111 int main()
112 {
113 float r = 1.5,h=3;
114 float pi = 3.14;
115 //圆周长
116 float CircumFerence = 2 * pi*r;
117 //圆面积
118 float CircleArea = pi*r*r;
119 //圆球表面积
120 float Surface_area_of_phere = 4 * pi * r * r;
121 //圆球体积
122 float SphereVolume = 4 / 3 * pi*r*r*r;
123 //圆柱体积
124 float CylinderVolume = pi*r*r*h;
125 printf("圆周长:>%0.2f\n", CircumFerence);
126 printf("圆面积:>%0.2f\n", CircleArea);
127 printf("圆球表面积:>%0.2f\n", Surface_area_of_phere);
128 printf("圆球体积:>%0.2f\n", SphereVolume);
129 printf("圆柱体积:>%0.2f\n", CylinderVolume);
130 system("pause");
131 return 0;
132 }
133
134 int main()
135 {
136 char c1, c2;
137 //int c1,c2;
138 c1 = getchar();
139 c2 = getchar();
140 printf("使用putchar输出:>");
141 putchar(c1);
142 putchar(c2);
143 printf("\n");
144 printf("使用printf输出:>");
145 printf("%c%c\n", c1,c2);
146 system("pause");
147 return 0;
148 }