Decode School

Decode School - The School for Problem Solvers
Welcome to My Blog.
Need Assignment / Project Guidance (or) Training in Python?

C Program to draw trapezium like below

Sample Input 1:

4

Sample Output 1:

123417181920
 567141516
  891213
   1011

Program or Solution

					    
							
#include<stdio.h>
int main()
{
	int n,num=1,i,j,k,l,space=0,m=1,number;
	printf("Enter row size:");
	scanf("%d",&n);
	number=n;
	for(i=0;i<n;i++)
	{
		for(j=1;j<=space;j++)
		{
			printf("-");
		}
		for(k=1;k<2*n-space;k++)
		{
			if(k%2==0)
				printf("%s","*");
			else
				printf("%d",num++);
		}
		printf("%s","*");
		for(l=1;l<2*n-space;l++)
		{
			if(l%2==0)
				printf("%s","*");
			else
			{
				printf("%d",m+number*number);
				m++;
			}
		}
		number--;

		space=space+2;
		printf("\n");
	}
	return 0;
}
					    
					

Program Explanation

Refer Video tutorial