117k views
4 votes
Write a demo main program that illustrates the work of BigInt(n) and prints the following sequence of big numbers 1, 12, 123, 1234, …, 1234567890, one below the other.

User Sjewo
by
5.7k points

1 Answer

6 votes

Answer:

The solution code is written in C++

  1. void BigInt(int n){
  2. int i, j;
  3. for(i = 1; i <= n; i++){
  4. for(j = 1; j <= i; j++){
  5. if(j < 10){
  6. cout<<j;
  7. }
  8. else{
  9. cout<<0;
  10. }
  11. }
  12. cout<<"\\";
  13. }
  14. }
  15. int main()
  16. {
  17. BigInt(10);
  18. return 0;
  19. }

Step-by-step explanation:

Firstly, create a function BigInt that takes one input number, n.

Next, create a double layer for-loop (Line 5-21). The outer loop is to print one big number per iteration and the inner layer is keep printing the accumulated individual digit for a big number. To ensure the big number is printed one below the other, we print a new line in outer loop (Line 19).

In main program, we call the function to print the big number (Line 26).

User Bvv
by
5.3k points