Write a function in C called RectArea() that returns an integer value equal to the area of the given rectangle
###### Posted by Samath
Last Updated: May 04, 2016

Use the following code to describe a rectangle. Assume the rectangle sides are parallel to the x and y axes (no rotation), and that the corners of the rectangle are located properly according to their compass designations in the structure.

struct point {
int x,y;
};
struct rect {
struct point ne,se,sw,nw;
};

Write a function called RectArea() that returns an integer value equal to the area of the given rectangle.

Solution:

#include<stdio.h>
struct point{
int x, y;
};
struct rect{
struct point ne, se, nw, sw;
};
int rectArea(struct rect *r){
int l, w;
l = (r->se.y)-(r->sw.y);
w = (r->sw.x) - (r->nw.x);
return l*w;
}
int main(int argc, char *argv[])
{
struct rect rectangle;
int x, y,area;
printf("Enter Points on NE\n");
printf("Enter x: ");
scanf("%d", &x);
printf("Enter y: ");
scanf("%d", &y);
rectangle.ne.x = x;
rectangle.ne.y = y;

printf("Enter Points on SE\n");
printf("Enter x: ");
scanf("%d", &x);
printf("Enter y: ");
scanf("%d", &y);
rectangle.se.x = x;
rectangle.se.y = y;

printf("Enter Points on NW\n");
printf("Enter x: ");
scanf("%d", &x);
printf("Enter y: ");
scanf("%d", &y);
rectangle.nw.x = x;
rectangle.nw.y = y;

printf("Enter Points on SW\n");
printf("Enter x: ");
scanf("%d", &x);
printf("Enter y: ");
scanf("%d", &y);
rectangle.sw.x = x;
rectangle.sw.y = y;

area = rectArea(&rectangle);
printf("Area of rectangle is: %d \n", area);
return 0;
}

###### Rectangle Area in C++
Samath | Jan 20, 2024
###### C program to calculate the area of a rectangle
Samath | Jan 02, 2017
###### C program that determines if a number is equal to zero
Samath | Nov 07, 2014
###### Rectangle Class in C++
Samath | Jan 17, 2024
###### C program that receives a positive float number and divides it by two until the result is less than or equal to zero
Samath | Jun 12, 2015
###### Polygon, Rectangle and Triangle Class in Python
Samath | Jan 20, 2024
###### Java program that calculate the area and perimeter of the rectangle and length of the diagonal
Samath | Feb 09, 2021
###### Python program that test if integer values can form a triangle
Samath | Nov 06, 2014
###### Java program that reads an integer and prints how many digits the number has
Samath | Feb 11, 2021
###### C++ Summing the digits in an integer
Samath | Jan 06, 2021
###### Recursive function that find the sum of digits in a integer using C++
Samath | Dec 24, 2014
###### Summing the Digits in an Integer using Python
Samath | Mar 02, 2015
###### C program that receives an integer number and determines if it is a prime number
Samath | Jun 01, 2015
###### Convert Integer to Roman Numeral using C#
Samath | Jan 20, 2024