c语言编程练习题:7-197 乘法口诀数列
作者:yunjinqi   类别:    日期:2023-06-04 19:08:19    阅读:419 次   消耗积分:0 分    

image.png

#include <stdio.h>
int main(){
    int a,b,n;
    int result;
    int arr[1000]={0};
    int count=0;
    int v1,v2;
    int index=0;
    if (scanf("%d %d %d",&a,&b,&n)!=EOF){
        if (n==1){arr[0] = a;}
        if (n==2){arr[0] = a;arr[1] = b;}
        if (n>2){
            while (count<n){
                if (count==0){arr[count] = a;count++;}
                if (count==1){arr[count] = b;count++;}
                if (count<n){
                    result = a*b;
                    if (result>9){
                        v1 = result/10;
                        v2 = result%10;
                        arr[count] = v1;
                        arr[count+1] = v2;
                        count+=2;
                    }
                    else{
                        arr[count]=result;
                        count+=1;
                    }
                    index++;
                    a = arr[index];
                    b = arr[index+1];
                }
            }
        }
        
    }
    // 打印数据
    for (int i=0;i<n;i++){
        printf("%d",arr[i]);
        if (i!=n-1){printf(" ");}
    }
    return 0;
}


版权所有,转载本站文章请注明出处:云子量化, http://www.woniunote.com/article/321
上一篇:c语言编程练习题:7-196 天梯赛的善良
下一篇:c语言编程练习题:7-198 自动编程