Thursday, December 18, 2014

Triangular steric pattern

//c++ program to display pattern like that

#include <iostream>
using namespace std;
int main()
{
 int size,temp_variable;   //declaring variables
 cout<<"Enter size = ";   //asking for input
 cin>>size;      //input
 temp_variable=size;    //store size in temporary variable
 if(size>0)
 {
  for(int i=1;i<=size;i++)   //outer loop controlling number of rows
  {
   for(int j=1;j<=temp_variable;j++)  //inner loop controlling number of columns
   {
    cout<<"* ";
   }
   temp_variable--;     //applying decrement
   cout<<endl;
  }
 }
 else
 {
  cout<<"Please enter size greater than zero.\n";
 }
 return 0;
}

No comments:

Post a Comment