suppose u r given a 4*3 rectangle like (take these values from user) Now u have to calculate the no. of squares in this rectangle like: No. of squares of dimension 1 is 12 No. of squares of dimension 2 is 6 No. of squares of dimension 3 is 2 No. of squares of dimension 4 is 0 Total no. of squares are 20.

Wednesday, February 3, 2010

#include<iostream.h>
#include<conio.h>
void main()
{    clrscr();
    int n,m,temp;
    cout<<"enter the length and breadth of the rectangle: ";
    cin>>n>>m;
    int k=n<m?n:m;
    for(int i=1;i<=k;i++)
    {       cout<<"number of cubes when dimension is"<<i<<" :";
        temp=(n-i+1)*(m-i+1);
        if(temp<0)
        cout<<"0";
        else if(temp==0)
        {    temp=(n>m?n:m)-k+1;
            cout<<temp;
        }
        else
        {    cout<<temp;
        }
        cout<<endl;
    }
    getch();
}

0 comments: