Code Competitions

Coding competition
Showing posts with label Advanced pattern designing. Show all posts
Showing posts with label Advanced pattern designing. Show all posts

Monday, 13 May 2013

Program to draw pattern and hoizontal and vertical sums

#include<stdio.h>
#include<conio.h>
void main()
{
    int i,j,sum[20]={0},a,n,ch=0,k,sum1;
    clrscr();
    printf("enter the number");
    scanf("%d",&a);
    if((a>=10)&&(a<=89))
    {
        for(i=0;i<=10;i++)
        {
            n=a+i;
            for(j=0;j<=i;j++)
            {
                printf("%d   ",n);
                sum[j]=sum[j]+n;
                n--;
            }
            printf("\n");
        }
    }
    else
    {
        printf("Invalid statment");
    }
    sum1=0;
    for(i=0;i<=10;i++)
    {
        k=sum[i];
        while(k>0)
        {
            k=k/10;
            ch++;
        }
        if(ch==2)
        {
        }
        else
        {
            printf("%-5d",sum[i]);
        }
            sum1=sum1+sum[i];
    }
    printf("\n%d",sum1);
    getch();
}