Sunday, December 28, 2014
Ex1- សរសេរកម្មវិធីដោយប្រើ Function ដើម្បីគណនាផ្ទៃក្រលារបស់ៈ ការ៉េ ចតុកោណ ត្រីកោណ រង្វង់
បង្កើតជា Menu ដើម្បីធ្វើការជ្រើសដូចខាងក្រោម៖
1 – គណនាក្រលាផ្ទៃការ៉េ
2 – គណនាក្រលាផ្ទៃរង្វង់
3 – គណនាក្រលាផ្ទៃចតុកោណ
4 – គណនាក្រលាផ្ទៃត្រីកោណ
+Code
#include<stdio.h>
#include<conio.h>
#include<math.h>
#define PI 3.1416
void Square()
{
float s,a;
printf("Input a =");scanf("%f",&a);
s=a*a;
printf("Area of square=%.2f\n",s);
}
void Circle()
{
float Area,Radius;
printf("Input Radius=");scanf("%f",&Radius);
Area=PI*Radius*Radius;
printf("Area of Circle=%.2f\n",Area);
}
void Rectangle()
{
float width,length,s;
printf("Input width=");scanf("%f",&width);
printf("Input length=");scanf("%f",&length);
s=width*length;
printf("Area of Rectangle=%.2f\n",s);
}
void Traingle()
{
float s,p,a,b,c;
printf("Input a=");scanf("%f",&a);
printf("Input b=");scanf("%f",&b);
printf("Input c=");scanf("%f",&c);
if (a<b+c)
{
if((b<a+c)&&(c<b+a))
{
p=(float)((a+b+c)/2);
s=sqrt(p*(p-a)*(p-b)*(p-c));
printf("Area of Traingle=%.2f\n",s);
}
else
printf("a,b,c are not size of traingle!\n");
}
else
printf("a,b,c are not size of traingle!\n");
}
void main()
{clrscr();
int done;
char c;
printf("========Calculate Geometry========\n");
printf("1-Area of Square\n");
printf("2-Area of Circle\n");
printf("3-Area of Rectangle\n");
printf("4-Area of Traingle\n");
printf("q-Quit\n");
printf("===============================\n");
done=0;
while(!done)
{
c=getchar();
switch(c)
{
case '1':
Square();break;
case '2' :
Circle();break;
case '3':
Rectangle();break;
case '4':
Traingle();break;
case 'q':
printf("Quit");done=1;break;
}
}
getch();
}
Labels:
cprogram
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment