Ask Question
29 May, 13:37

Write a program to generate all combinations of 1, 2 and 3 usingfor loop.

+1
Answers (1)
  1. 29 May, 16:16
    0
    C program for generating all combinations of 1, 2 and 3

    #include

    int comb (int a, int b, int c) / *defining function with parameters a, b and c of int type*/

    {

    for (a=1; a<4; a++) / /loop for the first integer

    {

    for (b=1; b<4; b++) / /loop for the second integer

    {

    for (c=1; c<4; c++) / /loop for the third integer

    printf ("One of the combination is / n%d %d %d", a, b, c);

    }

    }

    return 0;

    }

    int main () / /driver function

    {

    int a, b, c;

    printf ("Combinations are-");

    comb (a, b, c); //calling function

    return 0;

    }

    Output

    Combinations are-

    One of the combination is 1 1 1

    One of the combination is 1 1 2

    One of the combination is 1 1 3

    One of the combination is 1 2 1

    One of the combination is 1 2 2

    One of the combination is 1 2 3

    One of the combination is 1 3 1

    One of the combination is 1 3 2

    One of the combination is 1 3 3

    One of the combination is 2 1 1

    One of the combination is 2 1 2

    One of the combination is 2 1 3

    One of the combination is 2 2 1

    One of the combination is 2 2 2

    One of the combination is 2 2 3

    One of the combination is 2 3 1

    One of the combination is 2 3 2

    One of the combination is 2 3 3

    One of the combination is 3 1 1

    One of the combination is 3 1 2

    One of the combination is 3 1 3

    One of the combination is 3 2 1

    One of the combination is 3 2 2

    One of the combination is 3 2 3

    One of the combination is 3 3 1

    One of the combination is 3 3 2

    One of the combination is 3 3 3
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Write a program to generate all combinations of 1, 2 and 3 usingfor loop. ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers