Friday, April 26, 2013

number in pyramid before space in C++


#include <iostream>
using namespace std;
int main(){

int a;
int b;
cout<<"enter the number pyramid limit:";
cin>>b;
int nPyramid = 1;

int k=b;
for(a=1;a<=k;a++)
{


for(int i=0;i<b;i++)
{                   //for the spaces
cout<<nPyramid<<"\t";

nPyramid++;         //Increase the pyramid value by 1
}

nPyramid--; //Remove this line and see the effect
cout<<endl; //Next line
for(int i=1;i<=a;i++)
{ cout<<"\t";
}
b--;
}
}
output:-

number in pyramid space after in C++


#include <iostream>
using namespace std;
int main(){
int a;
int b;
cout<<"enter the number pyramid limit:";
cin>>b;
int nPyramid = 1;
int k=b;
for(a=1;a<=k;a++)
{
for(int i=0;i<b;i++)
{                   //for the spaces
cout<<"\t"<<nPyramid;

nPyramid++;         //Increase the pyramid value by 1
}

nPyramid--;                 //Remove this line and see the effect
cout<<endl;               //Next line
b--;
}
}