Home » C programs

C programs to display Pattern according to number of rows



In these C programs, we are going to learn how to print display patterns using asterisks where number of rows is given?
Submitted by Preeti Jain, on February 18, 2018

Example 1: When number of rows: 4

       *
      ***
     *****
    *******

Example 2: When number of rows: 5

        *
       ***
      *****
     *******
    *********

Here is the C program, that will read number of rows from user and print the display pattern of asterisks according to given input.

#include<stdio.h>

int main(){
	int num_of_rows,i,j;

	printf("Enter Number Of Rows");
	scanf("%d",&num_of_rows);

	for(i=1;i<=num_of_rows;++i)
	{
		for(j=1;j<=(2*num_of_rows-1);++j)
		{
			if(j>=(num_of_rows+1-i) && j<=(num_of_rows-1+i))
				printf("*");
			else
				printf(" ");
		}
		printf("\n");
	}
	return 0;
}





Was this page helpful? Please share with your friends...

Are you a blogger? Join our Blogging forum.



Comments and Discussions





© https://www.includehelp.com (2015-2018), Some rights reserved.




close Like other websites, this site uses cookies to deliver relevant ads based on your interest, by using our website, you acknowledge that you have read our privacy policy.