Remainders Solution


#include <stdio.h>

main() {
  int a, b;
  float a1, b1;

  printf("Enter two numbers a and b: ");
  scanf("%d %d", &a, &b);

  a1 = a;
  b1 = b;

  printf("Decimal part of quotient using floats: %f\n", (a1 / b1) - (a / b));
  printf("Integral Remainder using modulus: %d\n", a % b);

}

Discussion

scanf("%d %d", &a, &b); Get two integers from the user.
a1 = a;  b1 = b; Store the integers in floats.
printf("Decimal part of quotient using floats: %f\n", (a1 / b1) - (a / b)); Calculate the decimal part of the quotient by taking the difference of the float quotient and the integer quotient. Note the %f print mask to print a floating point variable.
printf("Integral Remainder using modulus: %d\n", a % b);
Calculate the remainder using the modulus function.





Return to Homepage    Return to Programming Pages
Updated November 29, 2005. For comments and questions, send email to Vector.x64 @ gmail.com (without the spaces).