Ask Question
8 January, 01:42

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

+2
Answers (1)
  1. 8 January, 03:10
    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?
Get an answer to your question ✅ “Write a program to generate all combinations of 1, 2 and 3 usingfor loop. ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers