C Program To Calculate Perimeter Of Rectangle | C Programs

C Program To Calculate the perimeter of rectangle or to find out in three different ways, using pointers, standard, and macros. Please do leave a comment here, if you have any doubts about the following code. We do help you out.

Using Standard

1)The formula for perimeter of rectangle is perimeter=2*(length+breadth)

2)We are calculating the perimeter by substituting the length and breadth values into related variables “length”,”breadth”,the calculated value will store into “perimeter” variable.

output:

Using Functions

1)Here we are using the function float perimeter(float l,float b) to calculate perimeter,which returns the float value.

2)We are calling the function using perimeter(l,b)where l,b are float type arguments

3)float perimeter(float l,float b) calculate the perimeter and return the value,that value will store into variable “p”

output:

Using Pointers

1)Here  *p,*l,*b are pointer variables

2)we are calling the function using perimeter(&l,&b,&p),here we are passing addresses

3)void perimeter(float *l,float *b,float *p) function calculate the perimeter ,the value will store into pointer variable *p

output:

Using Macros

1)The formula for perimeter of rectangle 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 *