Page Rank Checker

Saturday 5 July 2014

Produce Given Pattern With 1-10 Numbers Program In C


This article is from solution of Let Us C by Yashwant Kanetkar. I also posted many another articles regarding solutions of Let Us C. If you have any problem regarding solution then give comment, I will surely reply your question.

Q. Write a program to produce the following output:
                         1
                   2          3
               4        5         6
          7       8         9          10

Ans.

#include<stdio.h>
#include<conio.h>
void main()
{
    clrscr();
    int n, i=1, no_tab;
    for(n=1;n<=10;n++)
    {
        if(n==1||n==2||n==4||n==7)
        {
            printf("\n\n");
            if(n==1)
            printf("\t\t\t");
            if(n==2)
            printf("\t\t");
            if(n==4)
            printf("\t");
        }
        printf("\t\t%d",n);
    }
    getch();
}