+ 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?
8 ответов
+ 5
here is a less confusing way
char combine[100];
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.
+ 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.
+ 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
+ 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..
+ 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
+ 2
What is your definition of combine? Addition? Concatenation?
0
well i want to combine like if a=10 b=50 , then c is the combination of a and b which is 1050 like you mention. is it really possible to do this? bcuz i found nothing about this. Thank you.
0
alright. i will give it a try. Thank You Pradeep!