Creating Square, Rectangle, Multiply, slash using * (star) using C

In the process of learning the basic of C language people often create shapes using the *, and these shapes question are also asked in the interview question and selection exam of various companies so it is very good to learn how to make various shapes.

rectangle_star
Rectangle
we can also make multiply etc.

multiply_star
Multiply

Code for the above images it is in the order of images.

#include <iostream>
using namespace std;

int main() {
int size;
cout << "Enter Number ";
cin >> size;
cout << endl;
for(int i=0;i<size;i++){
for(int j=0;j<size;j++){
cout << "*";
}
cout << endl;
}
cout << endl;
for(int i=0;i<size;i++){
for(int j=0;j<size;j++){
if(i == j)
cout << "*";
else
cout << " ";
}
cout << endl;
}
cout << endl;
for(int i=0;i<size;i++){
for(int j=0;j<size;j++){
if( (size - i - 1) == j)
cout << "*";
else
cout << " ";
}
cout << endl;
}
cout << endl;
for(int i=0;i<size;i++){
for(int j=0;j<size;j++){
if( (size - i - 1) == j || i == j)
cout << "*";
else
cout << " ";
}
cout << endl;
}
cout << endl;
for(int i=0;i<size;i++){
for(int j=0;j<size;j++){
if(i==0 || i == (size -1)) // printing for the first and last line
cout << "*";
else if((j == 0 && i != size-1) || (j==size-1 && i != size-1)) // printing for the first and last column except first and last row
cout << "*";
else // putting space for everything else
cout << " ";
}
cout << endl;
}
return 0;
}

output for this program is
output_star_c
output

Thanks for being here.
Any problem or suggestion please comment below.

Comments

Popular posts from this blog

C/C++ program to check the Palindrome string.

Second Equation of motion, How to implement using C language

Third Equation of motion, How to implement using C language