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
}
}
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;
}
}
#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;
}
#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;
}
{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.
Reference:cprogramming-bd.com/c_page3.aspx#calculates the value of money
Using while loop, write a program which calculates the product of digits from 1 to 5 and also show these no's vertically.
CLS PRINT "PROGRAM: Calculate both perimeter/area of rectangle" PRINT INPUT " Length"; length INPUT "Breadth"; breadth PRINT PRINT "Perimeter: "; 2 * (length + breadth) PRINT " Area: "; length * breadth END
Write a C program to Draw a RAINBOW and fill the suitable colors ...
The area of rectangle is : 896.0
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
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.
61:71 1:71/61
int length int breadth int area= (length x breadth) print area
Write an equation for the perimeter, and solve it. Remember that the perimeter is the sum of all four sides.
Area of rectangle: 7 times 9 = 63 square unitsArea of rectangle: 9 times 7 = 63 square units
#include<stdio.h> void main() { float length, breadth, area, perimeter; printf("Enter the length & breadth of a Rectangle\n(length breadth): "); scanf("%f %f",&length,&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"); }
{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.
A = x times (x + 2) A = x squared + 2x
It's width to length ratio is 3 : 8.
The area of a rectangle with a width of x units and a length of (x + 3) units