answersLogoWhite

0


Best Answer

Commented code for a win32 console application:

#include //Include stdio.h for console input/output funcs

#include //Include conio.h for getch function (lol)

void main( )

{

int nWidth, nHeight; //Variables to hold width and height of rectangle

while( 1 ) //Infinite loop - can only be exited using "break;" (among others)

{

printf( "Enter rectangle width: " ); //Print text...

scanf( "%d", nWidth ); //Scan for user input

fflush( stdin ); //Flush user input

printf( "Enter rectangle height: " ); //Print text...

scanf( "%d", nHeight ); //Scan for user input

fflush( stdin ); //Flush user input

printf( "Area of rectangle with width of %d and height of %d is %d\n", nWidth, nHeight, nWidth*nHeight ); //Print text...

fflush( stdout ); //Flush output

//Now program will jump back to start of loop

}

}

User Avatar

Wiki User

14y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

9y ago

Assuming the width and height are natural values (whole numbers greater than 0), the vast majority of rectangles will have areas that are greater than their perimeters. The exceptions are finite:

1. where the width is 1 because 1*height is always less than (1+height)*2;

2. where the width is 2 because 2*height is always less than (2+height)*2;

3. where the width is 3 units and the height is no more than 6 units because 3*6 is the same as (3+6)*2, and;

4. when both the width and height are 4.

The following program will show this to be true, testing all rectangles in the range 1x1 though 10x10. Note that duplicates are not tested because 7x8 is the same as 8x7.

#include<iostream>

int main()

{

size_t max = 10;

for (size_t w=1; w<=max; w+=1)

for (size_t h=w; h<=max; h+=1)

if (h*w > (h+w)*2)

std::cout << "A rectangle of " << w << " by " << h << " has an area greater than its perimeter" << std::endl;

}

When width and height are real numbers, however, the range of exceptions is infinite. The following program tests widths in the range 0.01 to 5.00 in increments of 0.01, locating the smallest rectangles for a given width. When width reaches 4.0, the first rectangles that meet the criteria will be squares (such as 4.01x4.01) which are all excluded.

#include<iostream>

int main()

{

double max = 5.00, step = 0.01;

for (double w=step; w<=max; w+=step)

{

bool found = false;

for (double h=w; h<=max && !found; h+=step)

if (found = (h!=w) && (h*w > (h+w)*2))

std::cout << "A rectangle of " << w << " by " << h << " has an area greater than its perimeter" << std::endl;

}

}

This answer is:
User Avatar

User Avatar

Wiki User

14y ago

#include <iostream>

using namespace std;

int main()

{

double L, W, area;

cout<<"Enter length: ":

cin>>L;

cout<<"Enter width: ":

cin>>W;

area=L * W;

cout<<endl<< "Area of the square is: "<<area;

system("pause");

return 0;

}

This answer is:
User Avatar

User Avatar

Wiki User

14y ago

#include <iostream>

using namespace std;

int main()

{

double x, y;

cout << "Enter the length: ";

cin >> x;

cout << "Enter the height: ";

cin >> y;

cout << "The perimeter is: " << (x + y) * 2 << endl;

char wait;

cin >> wait;

return 0;

}

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Write a programme that calculates length and width of rectangle in c plus plus?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What is the area of a rectangle is the length is 16 and the primeter is 56?

The area of rectangle is : 896.0


The length of a rectangle is 3 inches greater than the width Write a polynomial that represents the area of the rectangle?

let x be the width let x+3 be the length The area of a rectangle is length X width Area=(x)(x+3) =x^2+3x


What do you write when your doing volume?

If you are dealing with the functions of a square or a rectangle, you write the answer, which is the formula. Length multiplied by the width equals the volume.


The width of a rectangle is 61 cm and its length is 71 cm Write the ratio of its width to its length as a fraction?

61:71 1:71/61


Write a program to accept length and breadth of a rectangle and then calculate its area and print it?

int length int breadth int area= (length x breadth) print area


The length of a rectangle is 13.6cm the perimeter of the rectangle is 37.8cm what is the width?

Write an equation for the perimeter, and solve it. Remember that the perimeter is the sum of all four sides.


If the length of a rectangle is 7 and the width is 9 what two multiplication equations can you write to represent the area of the rectangle?

Area of rectangle: 7 times 9 = 63 square unitsArea of rectangle: 9 times 7 = 63 square units


Write a C program to find the area and perimeter of you square ii rectangle?

#include&lt;stdio.h&gt; void main() { float length, breadth, area, perimeter; printf("Enter the length &amp; breadth of a Rectangle\n(length breadth): "); scanf("%f %f",&amp;length,&amp;breadth); area=length*breadth; perimeter=2*(length+breadth); printf(" Area of the Rectangle=%0.3f\n",area); printf("Perimeter of the Rectangle=%0.3f\n",perimeter); printf("(Press ENTER to exit.)"); getch(); printf("\n"); }


Write a program in pascal that calculates the area of a circle?

{Area s the area of cube} {Length is the length of one side of the cube} program AreaofCube; var Area,Length:real; begin write('Enter the length of cube: '); readln(Length); Area:=6*(Length*Length); writeln('The area of cube is ', Area, ' cm^2.'); end.


What is x The width and length of a rectangle are given by two consecutive odd integers. Write an expression for the area A of the rectangle. Use x for the shorter side of the rectangle.?

A = x times (x + 2) A = x squared + 2x


What is the answer to A rectangle with an area of 24 in.2 has a length of 8 inches and a width of 3 inches. What is the correct way to write the ratio of its width to length?

It's width to length ratio is 3 : 8.


Write a statement that does not represent a linear function?

The area of a rectangle with a width of x units and a length of (x + 3) units