Advertisement
jacknpoe

ABS ( A-B )

Oct 30th, 2013
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.52 KB | None | 0 0
  1. #include<cstdio>
  2. #include<cstdlib>
  3.  
  4. /* Pra ficar claro o problema do número absoluto, entre com os valores:
  5. /  10, 5 / 5, 10 / 0
  6. */
  7.  
  8. int main( void){
  9.     int a, b, a_b, b_a, abs_a_b;
  10.  
  11.     while( true) {
  12.         printf( "\nDigite o primeiro numero (zero para sair): ");
  13.         scanf   ( "%d", &a);
  14.         if( a == 0) exit( 0);
  15.         printf( "Digite o segundo numero: ");
  16.         scanf   ( "%d", &b);
  17.  
  18.         a_b = a - b;
  19.         b_a = b - a;
  20.         abs_a_b = ( ( a_b > 0 ) ? a_b : b_a);
  21.         printf( "\na-b: %d / b-a: %d / diferenca: %d\n\n", a_b, b_a, abs_a_b);
  22.     }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement