In: Computer Science
Use nested for loops to generate the following patterns: C++
*****
*****
*****
(no space between rows of asterisks)
*
**
***
****
*****
(Again, no empty lines between rows)
*
**
***
**
*
(no lines between rows)
Last one, let the user pick the pattern by specifying the number of rows and columns.
#include <iostream>
using namespace std;
int main() {
for(int i=0;i<3;i++)
{
for(int j=0;j<4;j++)
cout<<"*";
cout<<endl;
}
}
#include <iostream>
using namespace std;
int main() {
for(int i=0;i<=5;i++)
{
for(int j=0;j<i;j++)
cout<<"*";
cout<<endl;
}
}
#include <iostream>
using namespace std;
int main()
{
int i, j, rows;
printf("Enter number of rows: ");
scanf("%d",&rows);
for(int i=0;i<rows;i++)
{
for(int j=0;j<i;j++)
cout<<"*";
cout<<endl;
}
for(i=rows; i>=1; --i)
{
for(j=1; j<=i; ++j)
{
cout<<"*";
}
cout<<endl;
}
return 0;
}