1 solutions

  • 0
    @ 2025-11-5 19:23:19

    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

    Information

    ID
    19323
    Time
    1000ms
    Memory
    128MiB
    Difficulty
    (None)
    Tags
    # Submissions
    0
    Accepted
    0
    Uploaded By