+ 1

# c program can i combine 2 different variables into 1 another variable?

for example int b; int c; int a=printf("%d%d",b,c); is it possible to do this for C programming?

5th Dec 2019, 7:07 AM
GG GG + 5
here is a less confusing way char combine; int a = 123; int b = 456; int c; sprintf(combine, "%d%d", a, b); sscanf(combine, "%d", &c); printf("%d", c); >>> 123456 try to learn about sscanf and sprintf, it'll come in handy for you a lot of times.
5th Dec 2019, 8:53 AM
Shen Bapiro + 2
no, at least not like the way you mentioned in the question. tell us more specific that what kind of combining you want like:- int a=10,b= 50; so you want int c should store something combined value like c=1050; or like that so i think that is possible through some code.
5th Dec 2019, 7:18 AM + 2
yes!! this is possible. but remember you are dealing with integers so this process i think will do.. first: know the total size or we can say number of digits stored in "a" in this case a=10 so there are two digit value is stored is "a" second: c=a; //now c = 10 c=c*100; //now c =1000 //if there are three digit in a like a=100 so you need to do c=c*1000 c = c+b //now c=1000 +50 so we have c = 1050
5th Dec 2019, 7:31 AM + 2
the size of a can be also found using loop like- int size = 0; while(a != 0) { a=a/10; size++; } mess with all parts of the code this is the way to learn.🙌 and if you fail we will give you full code too.. learn from mistakes 👍👍 BEST OF LUCK..
5th Dec 2019, 7:37 AM + 2
hmmm.. well this look surely a better way 😂😂 ☝☝ here is the stupid code i was making... note: it will give wrong output if like a=11, b=022; then output c = 1122;😛😛 https://code.sololearn.com/ce70QxGJgp02/?ref=app
5th Dec 2019, 9:13 AM + 2   