-2

I will directly get to the point.

int a,b,c, Number;
a=0;
b=1;
c=2;

Number = (a*100)+(b*10)+(c*1);

printf("%d", Number);

Result is 12.

I also have another variable that which is equal to exactly 12.

int number2 = 12;

Now I have to check the difference between them. How do I do that?

blackwater7
  • 107
  • 1
  • 9
  • Try printf("%03d", Number); – Fabio_MO Mar 07 '18 at 10:58
  • https://stackoverflow.com/questions/153890/printing-leading-0s-in-c – L_Church Mar 07 '18 at 10:58
  • 2
    *I also have another variable that which is equal to exactly 12* -- what do you mean? `Number` is also exactly 12. – Ajay Brahmakshatriya Mar 07 '18 at 11:00
  • 1
    What exactly are you trying to do? Do you really always have three variables containing digits for the number? What does "check the difference" mean? How do you report the difference between the string "012" and the number 12? – vgru Mar 07 '18 at 11:00

1 Answers1

1

Just use a if statement like below:-

int diff = 0;
if ( Number > number2 )
{
    diff = Number - number2;
    printf("Number is greater than number2 by %d\n", diff);
}
else if( number2 > Number )
{
    diff = number2 - Number;
    printf("number2 is greater than Number by %d\n", diff);
}
else
     printf("Numbers are equal \n");
Abhijit Pritam Dutta
  • 5,521
  • 2
  • 11
  • 17