Thursday, December 18, 2014

Triangular number pattern

//c++ program to dispaly a pattern like that

//so user only has to enter the size of pattern
#include <iostream>
using namespace std;
int main()
{
 int size,temp_size;    //declaring variable
 cout<<"Enter size  = ";   //asking for output
 cin>>size;      //giving input
 temp_size=size;      //store size in a temporary variable named temp_size
 for(int i=1;i<=size;i++)    //outer loop controllin number of rows
 {
  for(int j=1;j<=temp_size;j++)  //inner loop controlling number of columns
  {
   cout<<j<<" ";
  }
  temp_size--;     //decrement
  cout<<endl;
 }
 return 0;
}

No comments:

Post a Comment