Need help thank you Write a series of statements to define a

Need help, thank you
Write a series of statements to define a rectangle array rectArr with 10 elements, allocate memory to this array and initialize the upper left corner, lower right corner and name as (0, 0), (1, 1) and \"Rect\" element in this array.

Solution

ANS:

#include <stdio.h>

int main()
{
   //Step-1
   // defining a structure point whith x and y as structure members
   struct point
   {
       int x;//x-position
       int y;//y-position
   };
   struct rectangle
   {
//creating nested structure(creating structure point object in rectangle)
       struct point upper_left,lower_right;
       char *name;
   };
   //step-2
   //structure rectangle array with 10 elements
   struct rectangle rectArr[10];
   int i;
   //step-3
   //initializing array elements
   for(i=0;i<10;i++)
   {
       //step-4
   //initializing upper left corner
   rectArr[i].upper_left.x=0;
   rectArr[i].upper_left.y=0;
   //step-5
   //initializing lower right
   rectArr[i].lower_right.x=1;
   rectArr[i].lower_right.y=1;
   //step-6
   //copying name
   strcpy(rectArr[i].name,\"Rect\");
   }
   //step-7
   //displaying Values
   for(i=0;i<10;i++)
   {
       printf(\"\ Array%d Elements :\",i+1);
printf(\"Upper Left Corner=(%d,%d),Lower Right Corner=(%d,%d) and Name=%s\ \",rectArr[i].upper_left.x,rectArr[i].upper_left.y,rectArr[i].lower_right.x,rectArr[i].lower_right.y,rectArr[i].name);
   }
return 0;
}

Need help, thank you Write a series of statements to define a rectangle array rectArr with 10 elements, allocate memory to this array and initialize the upper l

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site