Thursday, 3 August 2023

Print Inverted Cube / homocentric Cube Pattern using C language

 

#include<stdio.h>

#include<conio.h>

#include<math.h>

int main()

{

    int n,t,i,j,m;

    //clrscr();  // use this function to clear console / screen in TurboC++ 

    printf("\n pick a number: ");

    scanf("%d",&n);

    for(i=1-n;i<n;i++)

    {

        m=n-abs(i);

        for(j=n,t=1;t<=m;t++,j--)

            printf("%3d",j);

        if(j==0)

            j++;

        for(t=2*n-(m+1),j++;t>0;t--)

            printf("%3d",j);

        printf("\n");

    }

    //getch();  //use this function to hold console / screen in TurboC++

    return 0;

}