Ask Question

Write a program that prints the following 45 pairs of numbers:

11

21

22

31

32

33

41

42

43

44

51

...

+4
Answers (1)
  1. 24 May, 14:58
    0
    Here is code in C+ + to print the following 45 pairs of numbers:

    11 21 22 31 32 33 41 42 43 44 51 ...

    / / include header

    #include

    using namespace std;

    //main function

    int main () {

    //declare variables

    int count=0;

    int flag=1;

    / / for loop to print the pattern

    for (int i=1;; i++)

    {

    for (int j=1; j<=i; j++)

    {

    / / this will print the pairs in vertical manner

    cout<
    //cout<
    / / this will keep count to print only 45 pairs

    count++;

    / / if count is equal to 45 then it will break the inner loop

    if (count==45)

    {

    flag=0;

    break;

    }

    }

    / / if the flag is eqaul to 45 then it will break the outer loop

    if (flag==0)

    break;

    }

    return 0;

    }

    Explanation:

    First declare and initialize two variables "count=0" & "flag=1". Here variable

    "count" is use to print only 45 pairs and "flag" is used to break the loop when 45 pairs of numbers are printed. In the nested for loop, for every value of i, j will run from 1 to i and print i then j without any space. After every pair, count will incremented by 1. It will check if "count" is greater than 45 or not. If "count" is greater than 45 then it make flag=0 and break the loop. in the outer for loop, if flag is 0 then it break the outer for loop.

    Output:

    11 21 22 31 32 33 41 42 43 44 51 52 53 54 55 61 62 63 64 65 66 71 72 73 74 75 76 77 81 82 83 84 85 86 87 88 91 92 93 94 95 96 97 98 99
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Write a program that prints the following 45 pairs of numbers: 11 21 22 31 32 33 41 42 43 44 51 ... ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers