Ken H

Ken H

  • NA
  • 646
  • 358.8k

Print pyramid digit question?

Apr 28 2012 11:42 PM
hi all,
#include<iostream.h>
void main()
{
  int p,m,q,n;
  cout<<"enter the number of lines:";
  cin>>n;
  for(p=1;p<=n;p++)//control row
  {
  //to print spaces
  for(q=1;q<=n-p;q++)
  cout<<"  ";
  //to print numbers
  m=p;
  for(q=1;q<=p;q++)
  {
  cout.width(4);
  cout<<m++;
  }
  m=m-2;//the "m=m-2" In this role?
  for(q=1;q<p;q++)
  {
  cout.width(4);
  cout<<m--;
  }
  cout<<endl;
  }
}
now,I just want to know the role of the variable "m=m-2" in this.
thanks.

Answers (2)