1 22 111 2222 11111 make this code from for loop

0 votes
asked Nov 28 by Shahab Ali

14 Answers

+1 vote
answered Dec 1 by (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 by (2,230 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 by (520 points)
0 votes
answered Dec 2 by (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.
...