求s=a+aa+aaa+aaaa+aa...a的值,其中a是一個數字


規律:后面一個數是前面一個數*10+a
/*
求s=a+aa+aaa+aaaa+aa...a的值,其中a是一個數字。例如2+22+222+2222+22222(此時共有5個數相加),幾個數相加有鍵盤控制。
*/
#include<stdio.h>
#include<malloc.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include <iostream>
int main()
{
    int a,s=0;
    int i,n,t;
    scanf("%d%d",&a,&n);
    t=a;
    for(i=1;i<=n;i++){
        s+=a;
        a=a*10+t;
    }
    printf("%d\n",s);
    return 0;
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM