给定一个矩形的长度和宽度,我们需要找到它的面积和周长。
矩形是一个二维图形,包含四条边和四个角,每个角都是90度。矩形的所有边不相等,只有矩形的对边相等。矩形的对角线也具有相同的长度。
下面是矩形的示意图。
这里A代表矩形的宽度,B代表矩形的长度。
要找到矩形的面积,公式是:长度 x 宽度
矩形的周长是2 x (长度+宽度)。
Input: 20 30 Output: area of rectangle is : 600 perimeter of rectangle is : 100
START In Function int area(int a, int b) Step 1 -> Declare an integer ‘area’ and store a * b in it Step 2 -> Return area. In Function int perimeter(int a, int b) Step 1-> Declare an integer ‘perimeter’ and store 2*(a + b) in it Step 2-> Return perimeter In int main() Step 1 -> Declare two integers ‘length’, ‘breadth’ Step 2 -> Print area(length,breadth) Step 3 -> Print perimeter(length, breadth); STOP
#include<stdio.h> //function to calculate area int area(int a, int b) { int area = a * b; return area; } //function to calculate perimeter int perimeter(int a, int b){ int perimeter = 2*(a + b); return perimeter; } int main(){ int length= 20; int breadth = 30; printf("area of rectangle is : %d</p><p>",area(length,breadth)); printf("perimeter of rectangle is : %d",perimeter(length, breadth)); return 0; }
area of rectangle is : 600 perimeter of rectangle is : 100
以上是矩形的面积和周长的C程序的详细内容。更多信息请关注PHP中文网其他相关文章!