demo_3_20

2022/3/21 0:01:54

本文主要是介绍demo_3_20,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

  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 int main()
  8 {
  9     int n = 0;
 10     double a, single_num = 0.0,total_sum=0.0;
 11     //从标准输入获取数字
 12     scanf("%d %lf", &n, &a);
 13     for (int i = 0; i < n; i++)
 14     {
 15         single_num += a*pow(10, i);
 16         total_sum += single_num;
 17     }
 18     printf("%lf\n", total_sum);
 19     system("pause");
 20     return 0;
 21 }
 22 
 23 int main()
 24 {
 25     //求1-20的阶乘
 26     double total_sum = 0.0;
 27     //遍历获取[1,20]当中的每一个数字
 28     for (int i = 1; i <= 20; i++)
 29     {
 30         //对每一个数字进行阶乘
 31         double single_num = 1.0;
 32         for (int j = i; j > 0; j--)
 33         {
 34             single_num *= j;
 35         }
 36         //对每个数字阶乘的结果进行求和
 37         total_sum += single_num;
 38     }
 39     printf("%lf\n", total_sum);
 40     system("pause");
 41     return 0;
 42 }
 43 
 44 int main()
 45 {
 46     double total_sum = 0.0, sum1 = 0.0, sum2 = 0.0, sum3 = 0.0;
 47     //[1-100]
 48     for (int i = 1; i <= 100; i++)
 49     {
 50         //累加
 51         sum1 += i;
 52         //[1-50]
 53         if (i <= 50)
 54         {
 55             //累加
 56             sum2 += i*i;
 57         }
 58         if (i <= 10)
 59         {
 60             sum3 = 1.0 / i;
 61         }
 62     }
 63     total_sum = sum1 + sum2 + sum3;
 64     printf("%.2lf\n", total_sum);
 65     system("pause");
 66     return 0;
 67 }
 68 
 69 int main()
 70 {
 71     int a, b, c;
 72     //获取[100,999]的数字
 73     for (int i = 100; i <= 999; i++)
 74     {
 75         //获取三位数字中的每一位
 76         a = i / 100;
 77         b = i / 10 % 10;
 78         c = i % 10;
 79         //进行判断
 80         if (a*a*a + b*b*b + c*c*c == i)
 81         {
 82             printf("%d ", i);
 83         }
 84     }
 85     system("pause");
 86     return 0;
 87 }
 88 
 89 int main()
 90 {
 91     for (int data = 2; data <= 1000; data++)
 92     {
 93         int factor_sum = 0;
 94         for (int factor = 1; factor <= data / 2; factor++)
 95         {
 96             if (data%factor == 0)
 97             {
 98                 factor_sum += factor;
 99             }
100         }
101         //判断
102         if (factor_sum == data)
103         {
104             printf("%d its factors are ", data);
105             for (int factor = 1; factor < data /2; factor++)
106             {
107                 if (data%factor == 0)
108                 {
109                     printf("%d,", factor);
110                 }
111             }
112             printf("\n");
113         }
114     }
115     system("pause");
116     return 0;
117 }
118 
119 int main()
120 {
121     //a代表分子,b代表分母,total_sum代表分式之和
122     double a = 2.0, b = 1.0, total_sum = 0.0;
123     for (int i = 0; i < 20; i++)
124     {
125         total_sum = a / b;
126         //更新分子和分母
127         double tmp = a;
128         a = a + b;
129         b = tmp;
130     }
131     printf("%lf\n", total_sum);
132     system("pause");
133     return 0;
134 }
135 
136 int main()
137 {
138     //定义高度
139     double total_meter = 100.0;
140     //定义小球经过的米数
141     double ball_total_sum = 0.0;
142     for (int i = 0; i < 10; i++)
143     {
144         //下落+回弹
145         ball_total_sum += total_meter;
146         //回弹距离等于高度的一半
147         total_meter /= 2;
148         ball_total_sum += total_meter;
149     }
150     //第十次回弹的距离
151     ball_total_sum -= total_meter;
152     printf("小球经过%lf米,第十次回弹的距离为%lf\n", ball_total_sum, total_meter);
153     system("pause");
154     return 0;
155 }
156 
157 int main()
158 {
159     int day = 9;
160     int cur_day_count = 1;
161     int prev_day_count;
162     while (day > 0)
163     {
164         prev_day_count = (cur_day_count + 1) * 2;
165         //更新
166         cur_day_count = prev_day_count;
167         day--;
168     }
169     printf("第一天获取桃子的数量%d\n", prev_day_count);
170     system("pause");
171     return 0;
172 }
173 
174 int main()
175 {
176     //从标准输入当中获取a的值
177     float a, x0, x1;
178     scanf("%f", &a);
179     //计算x0和x1的值
180     x0 = a / 2;
181     x1 = (x0 + a / x0) / 2;
182     //判断是否小于10^-5次方
183     while (fabs(x0 - x1) >= 1e-5)
184     {
185         //更新x0和x1的值
186         x0 = x1;
187         x1 = (x0 + a / x0) / 2;
188     }
189     printf("[%f]的平方根为[%f]\n", a, x1);
190     system("pause");
191     return 0;
192 }
193 
194 int main()
195 {
196     //x0代表xn,x1代表xn+1,f代表数,f1代表导数
197     double x0, x1,f,f1;
198     //计算n+1的值
199     x1 = 1.5;
200     do
201     {
202         x0 = x1;
203         f = ((2 * x0 - 4)*x0 + 3)*x0 - 6;
204         f1 = (6 * x0 - 8)*x0 + 3;
205         x1 = x0 - f / f1;
206     } while (fabs(x1-x0)>=1e-5);
207     printf("方程1.5附近的根:%lf\n", x1);
208     system("pause");
209     return 0;
210 }
211 
212 
213 int main()
214 {
215     double left = -10, right = 10, mid;
216     double tmp = 10;
217     while (fabs(tmp) > 1e-5)
218     {
219         mid = (left + right) / 2;
220         tmp = ((2 * mid - 4)*mid + 3)*mid-6;
221         if (tmp > 0)
222         {
223             right = mid;
224         }
225         else if (tmp < 0)
226         {
227             left = mid;
228         }
229     }
230     printf("方程在(-10,10)之间的根为:%lf\n", mid);
231     system("pause");
232     return 0;
233 }
234 
235 
236 int main()
237 {
238     //打印上半部分-4行
239     for (int i = 0; i < 4; i++)
240     {
241         //打印空格
242         for (int j = 3 - j; j>0; j--)
243         {
244             printf(" ");
245         }
246         //打印星星
247         for (int j = 2 * i + 1; j > 0; j--)
248         {
249             printf("*");
250         }
251         printf("\n");
252     }
253     //下半部分-3行
254     for (int i = 0; i < 3; i++)
255     {
256         //打印空格
257         for (int j = i + 1; j>0; j--)
258         {
259             printf(" ");
260         }
261         //打印星星
262         for (int j = 7 - 2 * (i + 1); j > 0; j--)
263         {
264             printf("*");
265         }
266         printf("\n");
267     }
268     system("pause");
269     return 0;
270 }
271 
272 
273 int main()
274 {
275     //列举A的所有对战对象
276     for (int A = 'X'; A <= 'Z'; A++)
277     {
278         //列举B的所有对战对象
279         for (int B = 'X'; A <= 'Z'; B++)
280         {
281             //列举C的所有对战对象
282             for (int C = 'X'; A <= 'Z'; C++)
283             {
284                 if (A != 'X'&&C != 'X'&&C != 'Z'&&A != B&&A != C&&B != C)
285                 {
286                     printf("A对战%c,B对战%c,C对战%c\n", A, B, C);
287                 }
288             }
289         }
290     }
291     
292     system("pause");
293     return 0;
294 }
295 
296 int main()
297 {
298     int a = 0, n;
299     for (n = 0; n < 3; n++)
300     {
301         switch (a)
302         {
303         case 0:
304         case 1:a += 1;
305         case 2:a += 2; break;
306         case 3:a += 3;
307         default:a += 4;
308         }
309         printf("%d\n", a);
310     }
311     system("pause");
312     return 0;
313 }
314 
315 int fun(int (*s)[4], int n, int k)
316 {
317     int m, i;
318     m = s[0][k];
319     for (i = 0; i < n; i++)
320     {
321         if (s[i][k]>m) m = s[i][k];
322     }
323     return m;
324 }
325 int main()
326 {
327     int a[4][4] = { { 1, 2, 3, 4 }, { 11, 12, 13, 14 }, { 21, 22, 23, 24 }, { 31, 32, 33, 34 } };
328     printf("%d\n", fun(a, 4, 0));
329     system("pause");
330     return 0;
331 }
332 
333 
334 int main()
335 {
336     int s, t, A = 10;
337     double B = 6;
338     s = sizeof(A);
339     t = sizeof(B);
340     printf("%d,%d\n", s, t);
341     system("pause");
342     return 0;
343 }
344 
345 double f(double x)
346 {
347     return x*x + 1;
348 }
349 int main()
350 {
351     double a = 0;
352     int i;
353     for (i = 0; i < 30; i += 10)
354     {
355         a += f((double)i);
356         printf("%5.0f\n", a);
357     }
358     system("pause");
359     return 0;
360 }
361 
362 
363 int main()
364 {
365     int x;
366     scanf("%d", &x);
367     if (x <= 3);
368     else if (x != 10) printf("%d\n", x);
369     system("pause");
370     return 0;
371 }
372 
373 int main()
374 {
375     char a = 'H';
376     a = (a >= 'A'&&a <= 'Z') ? (a - 'A' + 'a') : a;
377     printf("%c\n", a);
378     system("pause");
379     return 0;
380 }
381 
382 #define SUB(a) (a)-(a)
383 int main()
384 {
385     int a = 2, b = 3, c = 5, d;
386     d = SUB(a + b)*c;
387     printf("%d\n", d);
388     system("pause");
389     return 0;
390 }

 



这篇关于demo_3_20的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程