Skip to main content

Featured

functions in Python

C++ program to print pattern of numbers with each line reversing the previous line

//C++ program to print pattern of numbers with each line reversing the previous line
#include<iostream.h>
#include<conio.h>
void main()
{
int i,k,t,a=1,s=0;
clrscr();
for(i=6;i>=1; i--)
{
  if(i%2==0)
  {
    for(k=1;k<=i;k++)
{
cout<<a<<"   ";
++a;
}
   cout<<"\n";
   t=a;
   }
 if(i%2!=0)
 {
  for(s=t+i-1;s>=t;s--,a++)
  {
  cout<<s<<"   ";
  }
 cout<<"\n";
 }
     
}
getch();
}

The output will be as following:

Comments

Popular Posts