Q:

C Program To Find Area of Rectangle

belongs to collection: Basic C Programming Examples

0

you have to make this program in the following way:

  • C Program To Find Area of Rectangle (Simple Way)
  • C Program To Find Area of Rectangle Using Function
  • C Program To Find Area of Rectangle Using Pointer
  • C Program To Find Area of Rectangle Using Macro

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

C Program To Find Area of Rectangle (Simple Way)

Algorithm

  • Program Start
  • Declare Variables
  • Input length and breadth From User
  • Calculate Area of Rectangle
  • Display Result
  • Program End

Program

//C Program To Find Area of Rectangle

#include<stdio.h>
void main()
{
	float l,b,area;

	printf("Enter length of rectangle: ");
	scanf("%f",&l);

	printf("Enter breadth of rectangle: ");
	scanf("%f",&b);

	area=(l*b);
	printf("Area of Rectangle : %f\n",area);

}

Output

Enter length of rectangle: 10
Enter breadth of rectangle: 12
Area of Rectangle : 120.000000

 

C Program To Find Area of Rectangle Using Function

Algorithm

  • Program Start
  • Declare Variables
  • Input length and breadth From User
  • Calling Function To Calculate Area of Rectangle
  • Calculating Area of rectengle
  • Display Result
  • Program End

Program

//C Program To Find Area of Rectangle Using Function 

#include<stdio.h>
void aor(float l, float b);
void main()
{
	float l,b;

	printf("Enter length of rectangle: ");
	scanf("%f",&l);

	printf("Enter breadth of rectangle: ");
	scanf("%f",&b);

	aor(l,b);
}
void aor(float l, float b)
{
    float area;

    area = (l*b);

	printf("Area of Rectangle : %f\n",area);
}

Output

Enter length of rectangle: 3
Enter breadth of rectangle: 5
Area of Rectangle : 15.000000

C Program To Find Area of Rectangle Using Pointer

Program

//C Program To Find Area of Rectangle Using Pointer 

#include<stdio.h>
void aor(float *l, float *b);
void main()
{
	float l,b;

	printf("Enter length of rectangle: ");
	scanf("%f",&l);

	printf("Enter breadth of rectangle: ");
	scanf("%f",&b);

	aor(&l,&b);
}
void aor(float *l, float *b)
{
    float area;
 
   //here l and b is a pointer variable 
    area = (*l)*(*b);

	printf("Area of Rectangle : %f\n",area);
}

Output

Enter length of rectangle: 30
Enter breadth of rectangle: 15
Area of Rectangle : 45.000000

C Program To Find Area of Rectangle Using Micro or #Define

Program

//C Program To Find Area of Rectangle Using #define

#include<stdio.h>
#define area(l,b) (l*b)
void main()
{
	float l,b,area;

	printf("Enter length of rectangle: ");
	scanf("%f",&l);

	printf("Enter breadth of rectangle: ");
	scanf("%f",&b);

	printf("Area of Rectangle : %f\n",area(l,b));

}

Output

Enter length of rectangle: 30
Enter breadth of rectangle: 50
Area of Rectangle : 150.000000

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Basic C Programming Examples

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
C Program To Find Area and Perimeter of Square... >>
<< C Program To Find Area of Triangle...