C Program To Calculate Perimeter Of Square | C Programs

C program to calculate the perimeter of square or to find out. Check out our program here, also just to let you know that we written the following C program in three different ways, using pointers, macros, and functions also.

Using Standard

1)The formula for perimeter of square is perimeter=4*s.

2)We are calculating the perimeter using the same formula by substituting the value “side” which is input to this program

3)The calculated value store into the variable “perimeter”

output:

Using Functions

1)Here  the function is float perimeter(float s) ,which is having float variable as argument and it return the float  value

2)We are calling the function  using perimeter(s), here “s” is float type variable,this “s” will pass toed perim

float perimeter(float s),calculated perimeter value 4*s will return to p=perimeter(s)

output:

Using Pointers

1)Here we are passing the addresses of s,p variables using function perimeter(&s,&p).

2)The values at that addresses &s,&p will store in to pointer variables *s,*p

3)The function void perimeter(float *s,float *p) calculate the perimeter of square and that value will store into pointer variable *p

output:

Using Macros

1)the formula 4*s was defined with the name area(s)

2)We have code as p=area(s),but area(s) means 4*s.

3)So p=4*s will be calculated and store in to p

output:

Add a Comment

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