用 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
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
JavaScript
PHP