135k views
4 votes
C programmig : Output all combinations of character variables a, b, and c, using this ordering:abc acb bac bca cab cbaSo if a = 'x', b = 'y', and c = 'z', then the output is: xyz xzy yxz yzx zxy zyxYour code will be tested in three different programs, with a, b, c assigned with 'x', 'y', 'z', then with '#', '$', '%', then with '1', '2', '3'.

2 Answers

3 votes

A C program to find all combinations of character variables:

void main ()

{

char f;

char s;

char t;

f = 'x';

s = 'y';

t = 'z';

System.out.print("" + f + s + t + " " + f + t + s + " " + s +f + t +

" " + s + t + f + " " + t + f + s + " " + t + s + f);

}

}

User Roland Sarrazin
by
5.5k points
4 votes

Answer:

// Here is code in C.

#include "stdio.h"

// create function to print all the combinations

void print_combi(char a,char b,char c)

{

// print all combinations of three characters

printf("%c%c%c %c%c%c %c%c%c %c%c%c %c%c%c %c%c%c\\",a,b,c,a,c,b,b,a,c,b,c,a,c,a,b,c,b,a);

}

// driver function

int main(void)

{

// create 3 char variable and initialize

char a='x',b='y',c='z';

// call the function

print_combi(a,b,c);

printf("\\");

// initialize with different character

a='1',b='2',c='3';

// call the function

print_combi(a,b,c);

printf("\\");

// initialize with different character

a='#',b='$',c='%';

// call the function

print_combi(a,b,c);

printf("\\");

return 0;

}

Step-by-step explanation:

Create three char variables a, b, c. First initialize them with x, y, z. then call the function print_combi() with three parameters . this function will print all the combinations of those characters.We can test the function with different values of all the three char variables.

Output:

xyz xzy yxz yzx zxy zyx

123 132 213 231 312 321

#$% #%$ $#% $%# %#$ %$#

User Sidmeister
by
4.8k points