+ 1

How to print below pattern using for loop?

XXXXX XXXX XXX XX X

5th Jan 2022, 3:12 PM
Bhupendra Dangwal
Bhupendra Dangwal - avatar
10 Antworten
+ 1
check this out: #include <iostream> using namespace std; int main() { int lines = 6, x = 6; for(int i=0; i<lines; i++) { for(int j=0; j<x; j++) { cout<<"X"; } cout<<endl; x--; } return 0; }
6th Jan 2022, 1:38 AM
Jamal Aldin Moshgi
Jamal Aldin Moshgi - avatar
+ 3
You can use an if-else statement to the second for loop and print X if first initial variable >= second else " "
5th Jan 2022, 4:43 PM
Simba
Simba - avatar
+ 2
Here's what you're looking for. https://code.sololearn.com/ctIAO5SefrJ7/?ref=app
5th Jan 2022, 8:22 PM
Abraham
Abraham - avatar
+ 2
#include <iostream> using namespace std; int main() { for(int l=5;l>=1;l--) { for(int s=1;s<=5-l;s++) { cout<<" "; } for(int v=1;v<=l;v++) { cout<<"X"; } cout<<endl; } return 0; } Outer most for loop is used to display lines and the inner for loop is used to print Spaces from the left side and the most inner for loop is used to print variable X on the screen. And last, statement "cout<<endl;" is used to move on next line.
6th Jan 2022, 4:29 AM
Muhammad Rizwan
Muhammad Rizwan - avatar
+ 2
Bhupender Singh #include<iostream> using namespace std; int main() { int n=5; for(int i=5;i>0;i--){ int space=n-i; for(int j=1;j<=space;j++){ cout<<" ";//for printing spaces } int star=i; for(int j=1;j<=star;j++){ cout<<"X"; } cout<<endl; } } Here is right solution for this pattern
7th Jan 2022, 8:51 AM
Vaneela Khatri
+ 1
Thanks man But this is not what I'm looking for
5th Jan 2022, 3:35 PM
Bhupendra Dangwal
Bhupendra Dangwal - avatar
+ 1
I have tried this one X XX XXX XXXX XXXXX but i dont know how to add space in the beginning.
5th Jan 2022, 3:59 PM
Bhupendra Dangwal
Bhupendra Dangwal - avatar
0
I will try
5th Jan 2022, 5:09 PM
Bhupendra Dangwal
Bhupendra Dangwal - avatar
0
for i in range(5): for j in range(5): if(j<i): print(" ") else: print("x") print("\n") In python
7th Jan 2022, 6:00 AM
Abhishek Kumar
Abhishek Kumar - avatar