Ask Question
19 March, 03:06

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

+2
Answers (1)
  1. 19 March, 03:34
    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 & 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