write a program to print the following pattern:-
Answers
Answer:
#this code is in python
for i in range(0, 5):
s = ["*"]*5
s[i] = i
for j in s:
print(j, end="")
else:
print(end="\n")
Explanation:
*********atul
QUESTION:-
- WAP to print the following pattern
1 * * * *
* 2 * * *
* * 3 * *
* * * 4 *
* * * * 5
Code:-
- This is done in QBASIC
CLS
FOR I=1 TO 5
FOR J=1 TO I
IF J=I
THEN PRINT I+" "
ELSE
PRINT "* "
ENDIF
NEXT J
NEXT I
END
__________
- This can also be done in Java
package Coder;
public class Pattern {
public static void main(String[] args) {
for (int i=1;i<=5;i++)
{
for (int j=1;j<=i;j++)
{
if(j==i)
System.out.print(i+" ");
else
System.out.print("* ");
}
for(int j=5;j>i;j--)
{
System.out.print("* ");
}
System.out.println();
}
}
}
•Output of this code Attached
__________
- This can also be done in python
for i in range(1,5+1,1):
for j in range(1,i+1,1):
if(j==i):
print(i,end=" ")
else:
print("* ",end="")
for j in range(5,i,-1):
print("* ",end="")
print()
#Code written by @swetank232894