Calculate the Area of a
Triangle
#include
#include
#include
void main()
{
int s, a, b, c, area;
clrscr();
printf("Enter the values of a, b and c
\n");
scanf("%d %d %d", &a, &b,
&c);
s = (a + b + c) / 2;
area = sqrt(s * (s - a) * (s - b) * (s -
c));
printf("Area of a triangle = %d
\n", area);
getch();
}
Output
Enter the values of a,
b and c
12 10 8
Area of a triangle =
39
Calculate the Area of a Circle
#include
#include
#include
#define pi 3.142
void main()
{
float radius, area;
clrscr();
printf("Enter the radius of a circle \n");
scanf("%f", &radius);
area = pi * pow(radius, 2);
printf("Area of a circle = %5.2f\n", area);
getch();
}
Output
Enter the radius of a circle
30
Area of a circle = 2827.80
Calculate the Simple Interest
#include
#include
void main()
{
float principal_amt, rate, simple_interest;
int time;
clrscr();
printf("Enter the values of principal_amt, rate and time \n");
scanf("%f %f %d", &principal_amt, &rate, &time);
simple_interest = (principal_amt * rate * time) / 100.0;
printf("Amount = Rs. %5.2f\n", principal_amt);
printf("Rate = Rs. %5.2f%\n", rate);
printf("Time = %d years\n", time);
printf("Simple interest = %5.2f\n", simple_interest);
getch();
}
Output
Enter the values of principal_amt, rate and time
12
10
5
Amount = Rs. 12.00
Rate = Rs. 10.00%
Time = 5 years
Simple interest = 6.00
Find out the Roots of a Quadratic Equation
#include
#include
#include
#include
void main()
{
float a, b, c, root1, root2;
float realp, imagp, disc;
clrscr();
printf("Enter the values of a, b and c \n");
scanf("%f %f %f", &a, &b, &c);
if (a == 0 || b == 0 || c == 0)
{
printf("Error: Roots cannot be determined \n");
exit(1);
}
else
{
disc = b * b - 4.0 * a * c;
if (disc < 0)
{
printf("Imaginary Roots\n");
realp = -b / (2.0 * a) ;
imagp = sqrt(abs(disc)) / (2.0 * a);
printf("Root1 = %f +i %f\n", realp, imagp);
printf("Root2 = %f -i %f\n", realp, imagp);
}
else if (disc == 0)
{
printf("Roots are real and equal\n");
root1 = -b / (2.0 * a);
root2 = root1;
printf("Root1 = %f\n", root1);
printf("Root2 = %f\n", root2);
}
else if (disc > 0 )
{
printf("Roots are real and distinct \n");
root1 =(-b + sqrt(disc)) / (2.0 * a);
root2 =(-b - sqrt(disc)) / (2.0 * a);
printf("Root1 = %f \n", root1);
printf("Root2 = %f \n", root2);
}
}
getch();
}
Output
Enter the values of a, b and c
45 50 65
Imaginary Roots
Root1 = -0.555556 +i 1.065740
Root2 = -0.555556 -i 1.065740
No comments:
Post a Comment