What will be the difference in writing code for a rectangle and a hollow rectangle(pattern)?

Answer

There will be differences in the if the condition of both the codes. so let us focus on that part of the code because the rest will be the same.

 

Rectangle:

No if condition is their.

for(int i=1;i<=row;i++){

for(int j=1;j<=col;j++){

cout<<"*";

}

cout<<endl;

}

 

Hollow rectangle:

 

for(int i=1;i<=row;i++){

for(int j=1;j<=col;j++){

if(i==1 || i==row || j==1 || j==col){

cout<<"*";

}

else{

cout<<" ";

}

}

cout<<endl;

}

All c++ Questions

Ask your interview questions on c

Write Your comment or Questions if you want the answers on c from c Experts
Name* :
Email Id* :
Mob no* :
Question
Or
Comment* :
 





Disclimer: PCDS.CO.IN not responsible for any content, information, data or any feature of website. If you are using this website then its your own responsibility to understand the content of the website

--------- Tutorials ---