Monday, August 26, 2019

WAP to display triangle of 1 and 0.

//Program to display:
1
1  0
1  0  1
1  0  1  0
1  0  1  0  1

#include<stdio.h>
void main()
{
    clrscr();
    int i,j,n,k=0,t=1;
    printf("Enter any number:");
    scanf("%d",&n);
    for( i=1; i<=n ; i++)
    {
         for(j=1 ; j<=i ; j++)
         {
              if(j%2 != 0)
                  printf("%d", t);
              else
                  printf("%d", k);
          }
          printf("\n");
    }
    getch();
}

Output:
Enter any number:5
1
1  0
1  0  1
1  0  1  0
1  0  1  0  1

   

No comments:

Post a Comment

Write a program to find gcd of two numbers using recursion.

About:  The process in which a function calls itself is called recursion and the corresponding function is called as recursive function. ...