程序添加两个整数
#include
int main() {
int number1, number2, sum;
printf("Enter two integers: ");
scanf("%d %d", &number1, &number2);
// calculating sum
sum = number1 + number2;
printf("%d + %d = %d", number1, number2, sum);
return 0;
}
输出
Enter two integers: 12
11
12 + 11 = 23
在此程序中,要求用户输入两个整数。这两个整数分别存储在变量number1和number2中 。
printf("Enter two integers: ");
scanf("%d %d", &number1, &number2);
然后,使用+
运算符将这两个数字相加,结果存储在sum变量中。
sum = number1 + number2;
最后, printf()
函数用于显示数字总和。
printf("%d + %d = %d", number1, number2, sum);