1. Using the online compiler
• Enter the code from the file
int main(int argc, char *argv[]) {
float f;
int a, b, c;
int quotient, remainder;
// Obtain integer values for a and b
printf("Enter the value for integer a: ");
scanf("%d", &a);
printf("Enter the value for integer b: ");
scanf("%d", &b);
printf("\n\n");
// Integer add, subtract, multiply, divide
c = a + b;
printf("%d + %d = %d\n", a, b, c);
c = a - b;
printf("%d - %d = %d\n", a, b, c);
c = a * b;
printf("%d * %d = %d\n", a, b, c);
quotient = a / b;
remainder = a % b;
printf("%d / %d = %d\ r %d\n\n\n", a, b, quotient, remainder);
// Floating point division without and without typecast.
f = a / b;
printf("%d / %d = %f (a and b are integers)\n", a, b, f);
f = (float)a / b;
printf("%f / %d = %f (a and b are integers but with a cast as a float)\n", (float)a, b, f);
Run the program. enter integer values for Enter 4 for a, and 5 for b.
The answer to your question is provided in the image:
Comments
Leave a comment