Signup/Sign In

C++ Program To Print A Given Pattern Or Series Like 12345, 5432, 234, 43, 3

Here, in this tutorial, we will see how to write the program for the given pattern and print the resultant series formed for the input number of terms by the user.

We believe that all the patterns covered in this section will help you understand this concept and visualize it better while forming your patterns, as such questions are very frequently asked in various interviews with a slight modification.

#include<iostream>
#include<stdio.h>
#include<math.h>
using namespace std;

int i,j,p=1,n,reverse;

int main()
{
  cout<<"Enter The Number To Print A Pattern\n";
  cin>>n;
  int dig=log10(n);

   cout<<"\n"<<n<<endl;  
  
  for(i=1;i<=dig;i++)
  {
   while (n != 0)
     {
        reverse = reverse * 10;
        reverse = reverse + n%10;
        n       = n/10;
     }
     n=reverse/10;
    cout<<n<<endl;
    reverse=0;
   }  
 return 0; 
}


12345, 5432, 234, 43, 3

Conclusion

Here, in this tutorial mainly, we have to focus on the pattern of the series for how it is changing concerning the number of terms.