Jump to content

C Source Code/Sum and reverse of two entered numbers

From Wikiversity
/* display sum of 2 digits, and the digits transposed */
#include <stdio.h>

int main(void)
{
  short rev, sum, dig1, dig2;

  printf("Enter 2 digits separated by a space: ");
  fflush(stdout);
  scanf("%hd%hd", &dig1, &dig2);
  sum = dig1 + dig2;
  rev = dig2 * 10 + dig1;
  printf("sum = %hd\nrev = %hd\n", sum, rev);

  /* indicate success */
  return 0;
}