C Program Area Of Triangle | C Programs

From the list of C programs Another program that we are published today – C Program Area Of Triangle. I wrote the following code in three different Ways. Hope you like it, You can even share the different Ideas if you have any.

C program Area of triangle(standard)

1)For calculating the area of triangle we need height and base of a triangle.The base value will substitute into the variable “base”,height value in the variable “height”.

2)By substituting base and height in the formula we will calculate area of triangle.


C program Area of triangle(function)

1)We are using the function area(float b,float h)to calculate the area of triangle.

2)area(b,h) calling the function which has float type of arguments.

3)The called function area(float b,float h) will calculate the area and return the value,the return value will assigned to the variable “a”.


C program Area of triangle(pointers)

1)We are calling the function by passing references as arguments in the calling function “area(&b,&h,&a)”.

2)The called function void area(float *b,float *h,float *area) calculate the area of triangle,by retrieving the values at the given addresses and substitute those values in the formula.The calculated value will store into the pointer variable “area”.


C program Area of triangle(macros)

1)area(b,h) is symbolic name to the expression (b*h)/2.

2)area(b,h) replaced with that expression given at #define.


Add a Comment

Your email address will not be published. Required fields are marked *