スイッチケースを使用して幾何学的図形の領域を見つけるCプログラム
問題
switch caseステートメントを使用して、長方形、正方形、三角形、円の領域を見つけます。ユーザーは、実行時にベース、高さ、側面、半径、幅、長さを入力して、すべての幾何学的図形の領域を計算する必要があります。
解決策
switch caseステートメントを使用して長方形、正方形、三角形、円の領域を見つけるソリューションを以下に説明します-
式
それぞれの幾何学的図形の面積を求める式は次のとおりです-
- 長方形の領域 =幅*長さ;
- 正方形の領域 =サイド*サイド;
- サークルの領域 =3.142 * radius * radius;
- 三角形の領域 =0.5 * base * height;
例
以下は、switch caseステートメントを使用して長方形、正方形、三角形、円の領域を見つけるためのCプログラムです。 −
#include <stdio.h>
void main(){
int fig_code;
float side, base, length, breadth, height, area, radius;
printf("-------------------------\n");
printf(" 1 --> Circle\n");
printf(" 2 --> Rectangle\n");
printf(" 3 --> Triangle\n");
printf(" 4 --> Square\n");
printf("-------------------------\n");
printf("Enter the Figure code\n");
scanf("%d", &fig_code);
switch(fig_code){
case 1:
printf(" Enter the radius\n");
scanf("%f",&radius);
area=3.142*radius*radius;
printf("Area of a circle=%f\n", area);
break;
case 2:
printf(" Enter the breadth and length\n");
scanf("%f %f",&breadth, &length);
area=breadth *length;
printf("Area of a Rectangle=%f\n", area);
break;
case 3:
printf(" Enter the base and height\n");
scanf("%f %f", &base, &height);
area=0.5 *base*height;
printf("Area of a Triangle=%f\n", area);
break;
case 4:
printf(" Enter the side\n");
scanf("%f", &side);
area=side * side;
printf("Area of a Square=%f\n", area);
break;
default:
printf(" Error in figure code\n");
break;
}
} 出力
上記のプログラムを実行すると、次の結果が得られます-
Run 1: ------------------------- 1 --> Circle 2 --> Rectangle 3 --> Triangle 4 --> Square ------------------------- Enter the Figure code 3 Enter the base and height 4 7 Area of a Triangle=14.000000 Run 2: ------------------------- 1 --> Circle 2 --> Rectangle 3 --> Triangle 4 --> Square ------------------------- Enter the Figure code 1 Enter the radius 8 Area of a circle=201.087997
-
平行四辺形の領域を見つけるJavaプログラム
この記事では、平行四辺形の面積を見つける方法を理解します。平行四辺形には、2対の平行な等しい反対側があります。ベースと、ベースとその反対側の平行な側との間の垂直距離である高さがあります。 平行四辺形の面積は、式-を使用して計算されます。 base * height i.e. b x h 以下は同じのデモンストレーションです- 入力 入力が-であると仮定します Base : 6 Height : 8 出力 必要な出力は-になります Area parallelogram is : 48 アルゴリズム Step 1 - START Step 2 - Declare three
-
台形の領域を見つけるJavaプログラム
この記事では、台形の領域を見つける方法を理解します。台形は、少なくとも1対の辺が互いに平行な四辺形の一種です。台形の平行な側面はベースと呼ばれ、台形の非平行な側面は脚と呼ばれます。台形とも呼ばれます。 台形の面積は、式-を使用して計算されます。 (height/2 * (side_1 + side_2). i.e. Area = ½ x (sum of the lengths of the parallel sides) x perpendicular distance between parallel sides 以下は同じもののデモンストレーションです。平行な辺aとbの長