Write a C++ program to print the following pattern
Attachments:
![](https://hi-static.z-dn.net/files/d11/abb1ceb4a3571169718d5f0f7e94d5a0.jpg)
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
Science,
9 months ago
Hindi,
9 months ago
Math,
1 year ago
Math,
1 year ago
India Languages,
1 year ago
India Languages,
1 year ago