求2+22+222+2222+22222
生活随笔
收集整理的這篇文章主要介紹了
求2+22+222+2222+22222
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
//求2+22+222+2222+22222的和
//2
//22=2*10^1+2*10^0
//222=2*10^2+2*10^1+2*10^0
//2222=2*10^3+2*10^2+2*10^1+2*10^0
//22222=2*10^4+2*10^3+2*10^2+2*10^1+2*10^0
//一個新數字的產生,新數字的位數(n)與組成他的表達式的個數相等
//表達式:2*10^(n)??? n的取值為0到n-1
int Creat_Num(int num,int n)
{int new_num=0;int count;for (count = 0; count < n; count++){new_num+=num * pow(10, count);}printf("%d\n", new_num);return new_num;
}
int main()
{system("color 0B");int num=2;int sum = 0;int i;//求累加和for (i = 1; i <=5; i++){sum+=Creat_Num(num, i);}printf("sum=%d\n", sum);system("pause");return 0;
}
總結
以上是生活随笔為你收集整理的求2+22+222+2222+22222的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: LTE(4G) - NR(5G) RB
- 下一篇: php读取json三级,php-流明从文