Write a program to display the following pattern.
*
* #
* # *
* # * #
* # * # *
Answers
Answered by
0
QUESTION:-
- To print the the following pattern
*
* #
* # *
* # * #
* # * # *
___________
CODE:-
- This can be done in QBASIC
CLS
PRINT"ENTER NO. OR ROWS"
INPUT R
FOR I=1 TO R
FOR J=1 TO I
IF J MOD 2=0
THEN PRINT "#"
ELSE
PRINT "*"
NEXT J
NEXT I
END
________________
- This can also be done in JAVA.
package Coder;
import java.util.*;
public class Pattern {
public static void main(String[] args) {
Scanner sc=new Scanner (System.in);
System.out.print("Enter a number:");
int n=sc.nextInt();
for (int i=1;i<=n;i++)
{
for (int j=1;j<=i;j++)
{
if(j%2==0)
System.out.print("# ");
else
System.out.print("* ");
}
System.out.println();
}
}
}
•Output of this code is attached
_______________
- This question can also be done in PYTHON
r=(int)(input("Enter a number:"))
for i in range(1,r+1):
for j in range(1,i+1):
if(j%2==0):
print("#",end=" ")
else:
print("*",end=" ")
print()
•Output of this code is attached
Attachments:
Similar questions