Following code is the solution for
1 22 111 2222 11111
Code in "C Programming Language"
#include <stdio.h>
int main()
{
int i,j, m=1, n=2;
for(i=1; i<=5; i++)
{
for(j=1; j<=i; j++)
{
if(i%2 == 1)
printf("%d", m);
else
printf("%d", n);
}
printf(" "); /* \n is replaced with space */
}
return 0;
}
Code in "Python Programming Language"
for i in range(1, 6):
for j in range(1, i+1):
if(i%2 == 1):
print(1, end="")
else:
print(2, end="")
print("", end=" ")
I assume that you are asking for the following output
1
22
111
2222
11111
If yes, then following code is the solution
written in "C Programming Language" :
#include <stdio.h>
int main()
{
int i,j, m=1, n=2;
for(i=1; i<=5; i++)
{
for(j=1; j<=i; j++)
{
if(i%2 == 1)
printf("%d", m);
else
printf("%d", n);
}
printf("\n");
}
return 0;
}
Written in "Python Programming Language" :
for i in range(1, 6):
for j in range(1, i+1):
if(i%2 == 1):
print(1, end="")
else:
print(2, end="")
print("\r")
Hope this helps..