Develop a C program that defines two functions, one to compute the area of a tri
ID: 3680779 • Letter: D
Question
Develop a C program that defines two functions, one to compute the area of a triangle, the other function to compute the circumference of a triangle. The program must include the function prototypes and call these functions from main.
Develop a computational model (with a C program) that computes the slope of a line between two points in a plane: P1 with coordinates (x1 , y1 ), and P2 with coordinates (x2,y2). The program should include two functions: main and slopef. The parameters of the second function (slopef) are the coordinates of the points in a plane. Use the coordinate values: (0,3/2) and (2,0).
Explanation / Answer
C Program to find the area of traingle and circumference of traingle
#include<stdio.h>
#include<math.h>
double area_of_triangle(double, double, double);
double circumference_of_triangle(double, double, double);
double area_of_triangle( double a, double b, double c )
{
double s, area;
s = (a+b+c)/2;
area = sqrt(s*(s-a)*(s-b)*(s-c));
return area;
}
double circumference_triangle( double a, double b, double c )
{
double circum;
circum = a+b+c;
return circum;
}
main()
{
double a, b, c,area,circumference;
printf("Enter the sides of triangle :");
scanf("%lf%lf%lf",&a,&b,&c);
area = area_of_triangle(a, b, c);
circumference = circumference_triangle(a, b, c);
printf("Area of triangle = %.2lf ", area);
printf("Circumference of triangle = %.2lf ", circumference);
return 0;
}
-----------------------------------------------------------------------------------------------------------------
C Program to find the Slope of the line between two points (x1,y1) and (x2,y2)
#include <stdio.h>
#include <math.h>
float slope(float x1,float x2,float y1,float y2)
{
float slo,dx,dy;
dx = x2 - x1;
dy=y2-y1;
slo=dy / dx;
return slo;
}
int main( void)
{
float x1,x2 ,y1 , y2 ,m;
printf("Enter the two points scale on the two axis X and Y : ") ;
scanf("%f%f%f%f", & x1, & x2 , & y1 , & y2 ) ;
m=slope(x1 , x2 , y1 , y2);
printf("Slope of the line with end points (%f, %f) and (%f, %f) = %f", x1, y1, x2, y2, m);
return 0;
}
----------------------------------------------------------------------------------------------------------------------------------------------------------
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.