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.

1 22 111 2222 11111 make this code from for loop

0 votes
asked Nov 28, 2019 by Shahab Ali

14 Answers

+1 vote
answered Dec 1, 2019 by Tushar Parashar (220 points)
#include<stdio.h>
void main()
{
    int i,n,no_,number_of_repeat;
    n=0;
    printf("Enter no. of repeatation:\t");
    scanf("%d", &number_of_repeat);
    lable:
    n++;
    i=1;
    if((n%2)==0)
    {
        no_=2;
    }
    else
    {
        no_=1;
    }
    for(i=1;i<=n;i++){
        printf("%d",no_);
    }
    printf("\t");

    if(n<number_of_repeat)
    {
        goto lable;
    }
}
0 votes
answered Dec 1, 2019 by gameforcer (2,950 points)

in python:

for i in range(5):
    for j in range(i+1):
        print((i%2) + 1, end='')
    print(end=' ')

0 votes
answered Dec 1, 2019 by Rohan Ghobade (520 points)
0 votes
answered Dec 2, 2019 by Ajay K S (140 points)

#include<iostream>

using namespace std;

int

main ()

{

  int i, n, j;

  cout << "enter number of times that you want to print\n";

  cin >> n;

  for (i = 1; i <= n; i++)

    {

      cout << " ";

      for (j = 1; j <= i; j++)

{

  if (i % 2 == 1)

    {

      cout << "1";

    }

  else

    {

      cout << "2";

    }

}

    }

}

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.
...