Write a C++ program to print the following pattern
Attachments:
Answers
Answered by
1
import java.util.Scanner; class MainClass
{
public static void main()
{
Scanner sc = new Scanner(System.in);
System.out.println("How many rows you want in this pattern?");
int rows = sc.nextInt();
System.out.println(" pattern....!!!");
for (int i = 1; i <= rows; i++)
{
for (int j = 1; j <= i; j++)
{ if(j%2=0)
{
System.out.print(0);
}
else
{
System.out.print(1);
}
}
System.out.println();
}
sc.close();
}
}
{
public static void main()
{
Scanner sc = new Scanner(System.in);
System.out.println("How many rows you want in this pattern?");
int rows = sc.nextInt();
System.out.println(" pattern....!!!");
for (int i = 1; i <= rows; i++)
{
for (int j = 1; j <= i; j++)
{ if(j%2=0)
{
System.out.print(0);
}
else
{
System.out.print(1);
}
}
System.out.println();
}
sc.close();
}
}
Similar questions
English,
8 months ago
Computer Science,
8 months ago
Math,
1 year ago
Math,
1 year ago
India Languages,
1 year ago
India Languages,
1 year ago