Pattern-7

 Pattern7


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 =numbers ; i>=1; i--)
     {
       for(j=0; j <numbers ; j++)
       {
         if(i%2==0)
          {
            if(j%2==0)
             {
              printf("0 ");
             }
             else
            {
             printf("1 ");
            }
           }
        else
        {
            if(j%2==0)
            {
             printf("1 ");
            }
            else
            {
            printf("0 ");
            }
        }
       }
        printf("\n");
     }
}


Java Program
import java.util.Scanner;

public class Pattern_7 {

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

}

0 Comments:

Post a Comment