给定两个数字A和B。任务是编写一个程序来求这两个数字的加法。
null
例子 :
Input: A = 2, B = 3Output: 5Input: A = 3, B = 6Output: 9
在下面添加两个数字的程序中,首先要求用户输入两个数字,然后使用 scanf() 函数并存储在变量中 和
.然后是变量
和
使用算术运算符添加
结果存储在变量中 总和 . 下面是添加两个数字的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