#include <stdio.h>
int main() {
int price,number,discount;
scanf("%d %d %d",&price,&number,&discount);
float total;
total=price*number*(100-discount)/100;
printf("C=%.2f",total);
return 0;
}
This code reads three integers (price, number, discount), calculates a total after applying a percentage discount, and prints the result with two decimal places. The calculation uses integer arithmetic, which may cause the result to be truncated to an integer before being stored as a float.
- The expression `(100-discount)/100` performs integer division, which discards the fractional part. Consider converting one of the operands to a floating-point type before division.
- The variable `total` is a float, but the multiplication and division are done entirely with integers. Think about how to ensure the division produces a fractional result.