📌  相关文章
📜  a+b+c 整个正方形 - C++ (1)

📅  最后修改于: 2023-12-03 15:13:14.553000             🧑  作者: Mango

[C++] a+b+c Whole Square

Introduction

In programming, a common problem is to add three numbers and return the result as a sum or product. In this challenge, we will write a C++ program that calculates a whole square using the formula a^2 + b^2 + c^2 + 2*(a*b + b*c + a*c), where a, b, and c are inputted by the user.

Code

Here is the code for the a+b+c Whole Square program in C++:

#include<iostream>

using namespace std;

int main(){

    int a,b,c,sum; 

    cout<<"Enter three numbers: "<<endl;
    cin>>a>>b>>c;

    sum=(a*a)+(b*b)+(c*c)+(2*(a*b+b*c+a*c));
    cout<<"The sum of the whole square of a,b and c is "<<sum<<"."<<endl;

    return 0;
}
Explanation

The program first includes the iostream header file, which provides input/output capabilities. The main function reads in three integer inputs from the user using cin. It then calculates the whole square using the formula described above, and stores the result in the integer variable sum. Finally, the program outputs the result using cout.

Conclusion

In this challenge, we have written a C++ program that calculates the whole square of three inputted numbers using a formula. This program demonstrates the use of input/output statements, arithmetic operators, and variable declarations in C++ programming.