Pattern-9

 Pattern9


C Program
#include <stdio.h>
#include <stdlib.h>
int main()
{
    int numbers,i,j;
    printf("Enter the Number of rows:");
    scanf("%d",&numbers);
    for(i =0 ; i<numbers; i++)
     {
       for(j=0; j<numbers ; j++)
       {
        printf("%d ",(i%2));
       }
        printf("\n");
     }
}



Java Program
import java.util.Scanner;

public class Pattern_9 {

	public static void main(String[] args) {
		Scanner S = new Scanner(System.in);
		System.out.print("Enter The number of Rows:");
		int n = S.nextInt();
		for(int i =0 ;i<n; i++)
		{
			for(int j=0; j<n; j++)
			{
				System.out.print((i%2)+ "  ");
			}
			System.out.print("\n");
		}
	}


}



Python Program
n = int(input("Enter numbe of rows: "))
for i in range(n):
    for j in range(n):
        if(i%2==0):
            print("0", end=" ")
        else:
            print("1",end=" ")
    print(" ")

0 Comments:

Post a Comment