用 C++ 编写的求面积的程序


我们给定了一个矩形的边长,我们的任务是从该边长打印出正方形的面积。

正方形是一种二维平面图形,有 4 条边,形成 4 个 90 度角,且所有边都相等。换句话说,我们可以说正方形是一种边长相等的矩形。

以下是对正方形的一种表示法:

正方形的面积等于边长 x 边长

示例

Input: 6
Output: 36
As the side is 6 so the output is 6*6=36
Input: 12
Output: 144

算法

START
   Step 1-> Declare a function int area(int side)
   In function area
      Declare a variable area and set it as side * side
      Return area
   End
   Step 2 -> Declare a function int main()
   In main Function
   Declare a variable side and Set a Value
   Call function area(side)
   End
STOP

示例

#include <iostream>
using namespace std;
//funcion to calculate area of square
int area(int side){
   int area = side * side;
   return area;
}
// Driver Code
int main(){
   int side = 40;
   cout <<"area of square is :"<<area(side);
   return 0;
}

输出

area of square is :1600

更新于: 23-Sep-2019

1K+ 浏览量

开启你的事业

完成课程,获取认证

立即开始
广告
© . All rights reserved.