WAP to print following pattern using for loop
$
$$
$$$
$$$$
$$$$$
Answers
Answered by
1
Answer:
C ode -
- n = int(input("Enter the number of rows: "))
- m = (2 * n) - 2.
- for i in range(0, n):
- for j in range(0, m):
- print(end=" ")
- m = m - 1 # decrementing m after each loop.
- for j in range(0, i + 1):
- # printing full Triangle pyramid using stars.
Explanation:
I think it's helpful to you
Answered by
35
—› Your Program:
//java program to print the pattern
import java.util.*;
public class pattern
{
public static void main (String args[] )
{
Scanner in = new Scanner(System.in);
int n, i, j;
System.out.println("Enter the no. of rows you want to print the pattern:");
n = in.nextInt();
for(i = 1; i <= n ; i++)
{
for(j = 1; j <= i; j++)
{
System.out.print("$");
{
System.out.print(' ');
}
}
}
----------------
—› Variable Description:
- n = To take input from the user for the number of rows.
- i, j= to run the loop
----------------
—› Output:
Enter the no. of rows you want to print the pattern:
5
$
$$
$$$
$$$$
$$$$$
-----------------
Similar questions