Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR C

pyramid pattern in c

"EASIEST EXPLANATION EVER"
/*
n=4
                *
               ***
              *****
             *******
*/

#include <iostream>
using namespace std;
int main() {
	int n=4; //indicates the number of rows.
    int max_breadth=(n-1)*2+1, mid=breadth/2; //max_breadth indicates the maximum no. of '*' in the last row.
    for(int i=0;i<n;i++)
    {
        int range_start=mid-i,range_end=mid+i;
        for(int j=0;j<max_breadth;j++)
        {
            if(j>=range_start && j<=range_end){
                cout<<"*";
            }
            else{
                cout<<" ";
            }
        }
        cout<<endl;
    }
    return 0;
}
 
PREVIOUS NEXT
Tagged: #pyramid #pattern
ADD COMMENT
Topic
Name
7+9 =