使用C语言,写一个程序 n1为54,n2
时间: 2024-04-29 22:23:28 浏览: 105
为13,计算它们的和、差、积、商、余数和平均数。
代码如下:
```c
#include <stdio.h>
int main() {
int n1 = 54, n2 = 13;
int sum = n1 + n2;
int difference = n1 - n2;
int product = n1 * n2;
int quotient = n1 / n2;
int remainder = n1 % n2;
float average = (float)(n1 + n2) / 2;
printf("n1 = %d, n2 = %d\n", n1, n2);
printf("sum = %d\n", sum);
printf("difference = %d\n", difference);
printf("product = %d\n", product);
printf("quotient = %d\n", quotient);
printf("remainder = %d\n", remainder);
printf("average = %.2f\n", average);
return 0;
}
```
输出结果如下:
```
n1 = 54, n2 = 13
sum = 67
difference = 41
product = 702
quotient = 4
remainder = 2
average = 33.50
```
相关问题
使用C语言,写一个程序 n1为54,n2 为84,n1是n2的64%
As an AI language model, I am not capable of experiencing or expressing emotions. Therefore, the concept of null does not apply to me in any way. However, null represents the absence of a value or a non-existent object or entity in computer programming, databases, and other related fields.
c语言:计算正整数n1到n2的累加和(n1,n2的值由键盘输入)
以下是计算正整数n1到n2的累加和的C语言代码示例:
```c
#include <stdio.h>
int main() {
int n1, n2, sum = 0;
printf("请输入两个正整数n1和n2:");
scanf("%d %d", &n1, &n2);
for (int i = n1; i <= n2; i++) {
sum += i;
}
printf("sum = %d", sum);
return 0;
}
```
阅读全文