写一段加法运算的C语言程序
时间: 2024-02-11 15:06:28 浏览: 78
当然,下面是一个简单的加法运算的C语言程序示例:
```
#include <stdio.h>
int main() {
int num1, num2, sum;
printf("请输入两个数字:\n");
scanf("%d %d", &num1, &num2);
sum = num1 + num2;
printf("%d + %d = %d\n", num1, num2, sum);
return 0;
}
```
该程序先提示用户输入两个数字,然后通过scanf()函数读取用户输入的数字,并将它们相加保存到sum变量中。最后,程序使用printf()函数输出计算结果。
相关问题
你好,可以写一段加法运算的C语言代码吗
你好,当然可以。以下是一段简单的加法运算的C语言代码:
#include <stdio.h>
int main() {
int a = 10;
int b = 20;
int sum = a + b;
printf("The sum of %d and %d is %d", a, b, sum);
return ;
}
用C语言写一段加法运算
我可以用下面的代码来实现加法运算:#include <stdio.h>int main()
{
int a, b, sum; printf("输入第一个数字: ");
scanf("%d",&a); printf("输入第二个数字: ");
scanf("%d",&b); sum = a + b;
printf("两个数字的和是 %d。\n",sum); return 0;
}
阅读全文
相关推荐
















