Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please write the attached \'C\' Programming assignments and submit c files and w

ID: 3797625 • Letter: P

Question

Please write the attached 'C' Programming assignments and submit c files and word/text docs are documented in the detailed instructions below. Thank you so much

****All programs must be written using the VC++ 2015 compiler****

A) Required Items/Software:

Visual C++ 2015 (Visual Studio 2015 Professional or Visual Studio Express 2015)

MS Word or Notepad WinZip (or similar)- for extracting files

5. Karnaugh is a poor farmer who has a very small field. He wants to reclaim wasteland in the kingdom to get a new field. But the king who loves regular shape made a rule that a settler can only get a rectangular land as his field. Thus, Karnaugh should get the largest rectangular land suitable for reclamation. In the examples below the largest rectangles are (shaded) 1 1 In the first example, there are 2 size 4 1 0 0 0 1 1 1 1 1 1 1 1 1 1 1 rectangles. In the second example, there is 1 1 1 0 1 1 0 size 4 rectangle. In the final example, there 0 0 1 0 0 1 are 4 size 4 rectangles. 1 1 0 0 The maps of the wastelands above are grids, where '1' represents a place suitable for reclamation and 0' represents a sandy place. Write a C program to find the largest rectangle consisting only of 1's in the map, and report the size of the rectangle. Let the user enter the size and values of the matrix up to size 6. The size of a rectangle is defined by the number of 1's in it. Note that there may be two or more largest rectangles of the same size, and values may "wrap around" or overlap to determine the size Finally, ask the user if he/she wishes to run the program again. Use a constant and error check. Refer to the sample output below Sample Run: Enter the size of square 21): 5 Enter the grid 0 1 0 1 1 0 1 0 1 0 0 0 1 0 0 0 0 1 1 0 1 0 1 0 0 The largest size rectangle is: 3 Run Again (Y/N) N Name the program: LargestRectanglesxx.c, where XX are your initials

Explanation / Answer

Output:

Enter The Size Of Square (<=21): 5

Enter The Grid:
0 1 0 1 1
0 1 0 1 0
0 0 1 0 0
0 0 1 1 0
1 0 1 0 0

Largest Size Rectangle Is : 3
RUN AGAIN (Y/N):

Progam :


#include<stdio.h>
#include<bits/stdc++.h>
using namespace std;
#define X 21

// Rows and columns in input matrix


// Finds the maximum area under the histogram represented
// by histogram. See below article for details.
// http://www.geeksforgeeks.org/largest-rectangle-under-histogram/
int maxHist(int row[],int C)
{
// Create an empty stack. The stack holds indexes of
// hist[] array/ The bars stored in stack are always
// in increasing order of their heights.
stack<int> result;

int top_val; // Top of stack

int max_area = 0; // Initialize max area in current
// row (or histogram)

int area = 0; // Initialize area with current top

// Run through all bars of given histogram (or row)
int i = 0;
while (i < C)
{
// If this bar is higher than the bar on top stack,
// push it to stack
if (result.empty() || row[result.top()] <= row[i])
result.push(i++);

else
{
// If this bar is lower than top of stack, then
// calculate area of rectangle with stack top as
// the smallest (or minimum height) bar. 'i' is
// 'right index' for the top and element before
// top in stack is 'left index'
top_val = row[result.top()];
result.pop();
area = top_val * i;

if (!result.empty())
area = top_val * (i - result.top() - 1 );
max_area = max(area, max_area);
}
}

// Now pop the remaining bars from stack and calculate area
// with every popped bar as the smallest bar
while (!result.empty())
{
top_val = row[result.top()];
result.pop();
area = top_val * i;
if (!result.empty())
area = top_val * (i - result.top() - 1 );

max_area = max(area, max_area);
}
return max_area;
}

// Returns area of the largest rectangle with all 1s in A[][]
int maxRectangle(int A[][X],int R,int C)
{
// Calculate area for first row and initialize it as
// result
int result = maxHist(A[0],C);

// iterate over row to find maximum rectangular area
// considering each row as histogram
for (int i = 1; i < R; i++)
{

for (int j = 0; j < C; j++)

// if A[i][j] is 1 then add A[i -1][j]
if (A[i][j]) A[i][j] += A[i - 1][j];


// Update result if area with current row (as last row)
// of rectangle) is more

result = max(result, maxHist(A[i],R));
}

return result;
}

// Driver code
int main()
{
int n=0;
int toMore=0;
printf("Enter The Size Of Square (<=21): ");
scanf("%d",&n);
do{
if(n<=21)
{
int i,j;
int A[n][X];;
printf(" Enter The Grid: ");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&A[i][j]);
}
}
printf(" Largest Size Rectangle Is : %d",maxRectangle(A,n,n));
printf(" RUN AGAIN (Y/N):");
char s;
scanf("%c",&s);
if(s=='Y')
toMore=1;
}
}while(toMore>0);

}