C Program To Calculate Perimeter Of Triangle | Programs

C Program to calculate the perimeter of triangle in three different ways. You can check the list of C programs here. We written the code in three different, with sample output and example program. Do leave a comment here at the end of the post.

Using Standard Method

1)Entered length ,breadth values of rectangle store in to length,breadth variables

2)using the formula perimeter=2*(length+breadth) we will calculate the perimeter value

3) That value will be store in to perimeter variable

output:

Using Functions

1)Here we are using perimeter(float l,float b)function to calculate perimeter of triangle

2)We are calling the perimeter(float l,float b)function using perimeter(l,b) here the variables type is float

3)Calculated value will be store in to the variable  “p”

output:

Using Pointers

1)Here we are using void perimeter(float *l,float *b,float *p)function which is having pointers as arguments, to calculate perimeter

2)perimeter(&l,&b,&p)  ,here we are passing l,b,p addresses

3)The calculated value by the function void perimeter(float *l,float *b,float *p) will store in to pointer variable p

output:

Using Macros

1)The formula 2*(l+b) was defined with the name perimeter(l,b)

2)perimeter(l,b)replaced with that expression given at #define.

output:

Add a Comment

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