C语言编写程序,输入两个整数num1和num2,计算并输出它们的和、差、积、商(用实数表示,保留2位小数点)与余数。
时间: 2024-05-23 12:15:27 浏览: 86
输出十六进制数和科学表示法的实数-谭浩强经典C++课件
好的,这是一个关于C语言编写计算器的问题。您可以这样编写程序来得到答案:
#include <stdio.h>
int main() {
int num1, num2;
float sum, difference, product, quotient, remainder;
printf("Please enter two integers: ");
scanf("%d %d", &num1, &num2);
// calculate sum, difference, product, quotient, and remainder
sum = num1 + num2;
difference = num1 - num2;
product = num1 * num2;
quotient = (float)num1 / (float)num2; // need to cast to float to get accurate division
remainder = num1 % num2;
// output results
printf("Sum is: %.2f\n", sum);
printf("Difference is: %.2f\n", difference);
printf("Product is: %.2f\n", product);
printf("Quotient is: %.2f\n", quotient);
printf("Remainder is: %.2f\n", remainder);
return 0;
}
阅读全文