How can i print the following pattern in c++ using for loop | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How can i print the following pattern in c++ using for loop

* * * * * * * * * *

22nd Nov 2016, 8:44 AM
beginner coder
1 Answer
+ 1
Im still learning c++ ,thats y i use a bunch of line of code but it exactly prints same output so i think you would't mind :) #include <iostream> using namespace std; int main() { int i,j,lines,k,num=1; cout<<"Enter the length"; cin>>lines; cout<<endl; for(i=1;i<=lines;i++) { for(j=lines-i;j>0;j--) { cout<<" "; } for(k=1;k<=i;k++) { cout<<" "; cout<<" "; cout<<"*"<<" "; } cout<<endl; } return 0; }
22nd Nov 2016, 2:01 PM
Dhruv Saxena
Dhruv Saxena - avatar