1 条题解

  • 0
    @ 2025-4-12 22:03:04

    C :

    #include<stdio.h>
    #include<math.h>
    int main()
    {
        int a;
        long sums=0;
        scanf("%d",&a);
        long sum[100];
        for(int i=0;i<a;i++)
        {
            if(!i)
                sum[i] = 2*(int)pow(10,i);
            else
                sum[i] = sum[i-1]+2*(int)pow(10,i);
            //printf("%ld\n",sum[i]);
            sums += sum[i];
        }
        printf("%ld\n",sums);
        return 0;
    }
    
    

    C++ :

    #include<iostream>
    using namespace std;
    int main()
    {
    	long long s = 0, t = 2, n;
    	cin >> n;
    	while(n--)
    	{
    		s += t;
    		t = t * 10 + 2;
    	}
    	cout << s << endl;
    	return 0;
    }
    
    • 1

    C语言程序设计教程(第三版)课后习题6.3

    信息

    ID
    2701
    时间
    1000ms
    内存
    128MiB
    难度
    (无)
    标签
    递交数
    0
    已通过
    0
    上传者