Logo  

CS256 - Fundamentals of Structured Programming

Displaying exercises/e4/solution/h3.c

#include <stdio.h>
/**
 * Use scanf to read two integers from the user (a and b), then print the values
 * added, subtracted, multiplied, divided and modulus with each other:
 * Example input/output:
 * Enter a: 5
 * Enter b: 10
 * 5 + 10 = 15
 * 5 - 10 = -5
 * 5 * 10 = 50
 * 5 / 10 = 0
 * 5 % 10 = 5
 */
int main(void)
{
  int a, b;

  printf("Enter a: ");
  scanf("%d", &a);
  printf("Enter b: ");
  scanf("%d", &b);
  
  printf("%d + %d = %d\n", a, b, a+b);
  printf("%d - %d = %d\n", a, b, a-b);
  printf("%d * %d = %d\n", a, b, a*b);
  printf("%d / %d = %d\n", a, b, a/b);
  // Again, use two %% for a single % in the output.
  printf("%d %% %d = %d\n", a, b, a%b);

  return 0;
}