Pattern Printing

Print this pattern. you can use any language to print this. and you are not allowed to use any predefined functions in order to print this.

The complexity should be low. 
Show comments
Hide comments

3 comments:

  1. https://ideone.com/I3EVIs

    def printSpaces(n):
    for i in range(n):
    print(" ",end=" ")

    def printSqNum(k,n):
    for i in range(k,k+n):
    print(i**2,end=" ")

    k = 1
    n = 5

    for i in range(n):
    printSpaces(n-i-1)
    printSqNum(k,2*i+1)
    k = k + (2*i+1)
    print("\n")

    ReplyDelete
  2. //This program is in C
    #include

    int main()
    {
    int i,j,k,n,value=1;
    printf("Enter the no. of rows: ");
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
    for(j=1;j<=n-i;j++)
    {
    printf(" ");
    }
    for(k=1;k<=2*i-1;k++)
    {
    printf("%d ",value*value);
    value++;
    }
    printf("\n");
    }

    return 0;
    }

    ReplyDelete