zoukankan      html  css  js  c++  java
  • 【编程小题目7】求s=a+aa+aaa+aaaa+aa...a的值

    题目:求s=a+aa+aaa+aaaa+aa...a的值,其中a是一个数字。例如2+22+222+2222+22222(此时共有5个数相加),
    几个数相加有键盘控制

    #include <iostream>
    #include <string>
    using namespace std;

    long Function(int number, int n)
    {
      if(n == 1)
      {
        return number;
      }
      else
      {
        return Function(number ,n - 1) * 10 + number;
      }
    }

    int main()
    {
      int Count, Number;
      long Sum = 0;
      cin >> Number >> Count;
      cout << "Sum = ";
      for(int i = 1; i <= Count; i++)
      {
        int Temp = Function(Number, i);
        if(i != Count)
        {
          cout << Temp << " + ";
        }
        else
        {
          cout << Temp << " = ";
        }
        Sum += Temp;
      }

      cout << Sum << endl;

      return 0;
    }

  • 相关阅读:
    GCC编绎详解
    GUN C/C++ __attribute__ 用法 转
    rust 参考的资料 转
    Eclipse环境安装rust
    GNU Debugger for Windows----GDB
    minGW cygwin gnuwin32
    tdm-gcc
    GNU tools
    The MinGW and mingw-w64 projects.----GCC
    crosstool-NG
  • 原文地址:https://www.cnblogs.com/FoxShark/p/4441156.html
Copyright © 2011-2022 走看看