for example, i want to combine two number 6 and 8 and it will equal 68. is this possible in C?
int a = 6, b = 8,c;
c=ab;
and c will = 68.
for example, i want to combine two number 6 and 8 and it will equal 68. is this possible in C?
int a = 6, b = 8,c;
c=ab;
and c will = 68.
Jump to Postfor example, i want to combine two number 6 and 8 and it will equal 68. is this possible in C?
int a = 6, b = 8,c; c=ab;
and c will = 68.
Yes it is possible, but not the way you have shown. Your assignment statement assigns …
for example, i want to combine two number 6 and 8 and it will equal 68. is this possible in C?
int a = 6, b = 8,c; c=ab;
and c will = 68.
Yes it is possible, but not the way you have shown. Your assignment statement assigns the value of the variable ab to the variable c. The variable ab has not been defined.
It also depends a lot on what you mean by combine. What do you want to happen if a==56 and b==24? Similarly for a==25 and b==5? Or a=='6' (the character displayed as 6) and b=='8'?
So please explain what the "larger" problem or context is?
what i mean is for example
a=256 and b=10
i want to combine them so that they would be 25610.
or
a=19, b=20
it would combine to 1920.
is this possible?
Yes, it's possible. It would be something like this...
int multiplier = /* multiply by 10, 100, 1000, whatever based on the number of digits in b */
int combine = (multiplier * a) + b;
Your job is to figure out how many digits b has. There are a few ways to do that. log10 and pow from cmath might help, and / or use the / and % operators in a loop to figure it out or write your own helper function(s). Or perhaps use the itoa function if available or the snprintf(or sprintf if you're careful) function to turn b into a string, then take the length of that string.
http://www.cplusplus.com/reference/clibrary/cmath/
http://www.cplusplus.com/reference/clibrary/cstdlib/itoa/
http://libslack.org/manpages/snprintf.3.html
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.