I am trying to do this program but not able to get output can anyone help me
Hi Harish,
Use this code it will work...to get more understand on the logic i kept more spaces..if you don't want u can comment those statements.
/*
Program : Pattern Program of printing... 1 2 3 2 3 4 5 4 3 4 5 6 7 6 5 4 5 6 7 8 9 8 7 6 5
Author : Rajanikanth
Language: C++
Email : [email protected]
*/
#include<iostream>
using namespace std;
//1 2 3 2 3 4 5 4 3 4 5 6 7 6 5 4 5 6 7 8 9 8 7 6 5
int main()
{
int num, noft; //number of times
int rep=0; //repetition
cout<<"How many times you want to repeat this pattern...";
cin>>noft;
for(int cnt=1; cnt<=noft; cnt++)
{
for(num=cnt; num<=cnt+rep; num++)
cout<<num<<" ";
for(num=num-2; num>=cnt; num--)
cout<<num<<" ";
cout<<" ";
rep++;
}
}