用C语言编写的两个整数相加程序

给定两个数字A和B。任务是编写一个程序来求这两个数字的加法。

null

图片[1]-用C语言编写的两个整数相加程序-yiteyi-C++库

例子 :

Input: A = 2, B = 3Output: 5Input: A = 3, B = 6Output: 9

在下面添加两个数字的程序中,首先要求用户输入两个数字,然后使用 scanf() 函数并存储在变量中 A B .然后是变量 A B 使用算术运算符添加 + 结果存储在变量中 总和 . 下面是添加两个数字的C程序:

C

// C program to add two numbers
#include<stdio.h>
int main()
{
int A, B, sum = 0;
// Ask user to enter the two numbers
printf ("Enter two numbers A and B : ");
// Read two numbers from the user || A = 2, B = 3
scanf ("%d%d", &A, &B);
// Calculate the addition of A and B
// using '+' operator
sum = A + B;
// Print the sum
printf ("Sum of A and B is: %d", sum);
return 0;
}


输出 :

Enter two numbers A and B : 2 3Sum of A and B is: 5

© 版权声明
THE END
喜欢就支持一下吧
点赞10 分享