Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.
Login
Login
OnlineGDB Q&A
Questions
Unanswered
Tags
Ask a Question
Ask a Question
how can I print this using for loop
0
votes
asked
Sep 24, 2018
by
Arjun
x1
x1x2
x1x2x3
x1x2x3x4
Your answer
Your name to display (optional):
Email me at this address if my answer is selected or commented on:
Email me if my answer is selected or commented on
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please
log in
or register.
4 Answers
0
votes
answered
Sep 24, 2018
by
pushpesh kumar
#include<stdio.h>
int main()
{
int i,j;
for(i=1;i<=4;i++)
{
for(j=1;j<=i;j++)
{
printf("X%d ",i);
}
printf("\n");
}
return 0;
}
commented
Sep 24, 2018
by
anonymous
print on j not i
Your comment on this answer:
Your name to display (optional):
Email me at this address if a comment is added after mine:
Email me if a comment is added after mine
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please
log in
or register.
0
votes
answered
Sep 24, 2018
by
Ritik Bansal
(
140
points)
FOR PYTHON:--
for i in range(1,5):
for j in range(1,i+1):
print('x'+str(i),end='')
print()
commented
Sep 24, 2018
by
Ritik Bansal
(
140
points)
if you want extra space add print() after previous print()
commented
Sep 24, 2018
by
Ashish
Thank you but it’s printing
X1
X2X2
X3X3X3
X4X4X4X4
Your comment on this answer:
Your name to display (optional):
Email me at this address if a comment is added after mine:
Email me if a comment is added after mine
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please
log in
or register.
0
votes
answered
Sep 24, 2018
by
anonymous
int main()
{
cout<<"Hello World";
for (int i=0;i<5;i++){
for(int j=0;j<i;j++){
cout<<"x"<<j+1;
}
cout<<endl;
}
return 0;
}
Your comment on this answer:
Your name to display (optional):
Email me at this address if a comment is added after mine:
Email me if a comment is added after mine
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please
log in
or register.
0
votes
answered
Sep 24, 2018
by
anonymous
int main()
{
for (int i=0;i<5;i++){
for(int j=0;j<i;j++){
cout<<"x"<<j+1;
}
cout<<endl;
}
return 0;
}
Your comment on this answer:
Your name to display (optional):
Email me at this address if a comment is added after mine:
Email me if a comment is added after mine
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please
log in
or register.
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...