AMCAT Coding Questions asked in Programming Section Number Pattern 3

Program to print the given number pattern


Example: 
Input N:
Output:

/**
 * C program to print the given 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=i; j<=(i*i); j += i)
        {
            printf("%-3d", j);
        }
 
        printf("\n");
    }
 
    return 0;
}
</stdio.h>



Enter N: 5
1
2  4
3  6  9
4  8  12 16
5  10 15 20 25

No comments:

Post a Comment