比方这里有一个高度为7英寸,宽度为5英寸的矩形,我们如何用C言语盘算它的周长和面积。
下面我们经由过程细致的代码示例为人人细致引见其解决要领。
1.C编程:矩形的周长
周边是缭绕二维外形的途径。这个词来自希腊语peri(around)和meter(measure)。周长可用于盘算缭绕院子或花圃所需的围栏长度。关于只要两个差别边长的矩形,比方x和y,周长即是2x + 2y。
2.C编程:矩形地区
二维图形的地区描述了外形掩盖的外表量。您能够以牢固大小的平方单元丈量面积,平方单元为平方英寸,平方厘米或平方英里等。矩形地区的公式运用乘法: 长度•宽度=面积。四边长度相称的矩形是正方形。
c盘算周长和面积的代码以下:
#include <stdio.h> /* height and width of a rectangle in inches */ int width; int height; int area; int perimeter; int main() { height = 7; width = 5; perimeter = 2*(height + width); printf("Perimeter of the rectangle = %d inches\n", perimeter); area = height * width; printf("Area of the rectangle = %d square inches\n", area); return(0); }
盘算结果显现为:
Perimeter of the rectangle = 24 inches Area of the rectangle = 35 square inches
也就是矩形的周长= 24英寸, 面积= 35平方英寸。
盘算流程也能够以下图所示:
本篇文章就是关于用C言语盘算矩形的周长和面积的要领引见,异常简朴易懂,愿望对须要的朋侪有所协助!
以上就是如何用C言语盘算矩形的周长和面积?(附代码)的细致内容,更多请关注ki4网别的相干文章!