AMCAT Coding Questions asked in Programming Section Number Pattern 1

Program to print the given number pattern



Example:
 
Input N: 5
Output:

/**
 * C program to print triangle 0, 1 number pattern
 */
 
#include <stdio.h>
 
int main()
{
    int i, j, N;
 
    printf("Enter N: ");
    scanf("%d", &N);
 
    for(i=1; i<=N; i++)
    {
        for(j=1; j<=i; j++)
        {
            if(i==1 || i==N || j==1 || j==i)
            {
                printf("1");
            }
            else
            {
                printf("0");
            }
        }
 
        printf("\n");
    }
 
    return 0;
}



Enter N: 5
1
11
101
1001
11111

No comments:

Post a Comment