In this, we are going to see how to print the above very simple pattern of special characters, using nested for loops in C++.
The code given below can be used for TURBO C++ Compiler:-
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int rows;
cout << "\nEnter the number of rows\n";
cin >> rows;
cout << endl;
for (int i = 1; i <= rows; i++)
{
for (int j = 1; j <= rows; j++)
{
cout <<"@";
}
cout << "\n";
}
getch();
}
The code given below can be used for g++/gcc Compiler:-
#include<iostream>
using namespace std;
int main()
{
int rows;
cout << "\nEnter the number of rows\n";
cin >> rows;
cout << endl;
for (int i = 1; i <= rows; i++)
{
for (int j = 1; j <= rows; j++)
{
cout <<"@";
}
cout << "\n";
}
return 0;
}
#ENJOY CODING
Post a Comment
FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP