18/06/2016

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

Problem :-Write C++ Program To Print A Given Pattern Or Series Given Below .

12345
5432
234
43
3

Or Series Like :-12345 , 5432,234,43,3

Logic :- First Calculate A Length Digit Like 12345 Has 5 Digit By Using ( dig=log10 )After That Enter A Number To Reverse A Digit After That Divide By 10  Repeat The Process Again And Again .

Solution :-

#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; 
}

Output:-

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


Previous Post
Next Post

post written by:

Hi, I’m Ghanendra Yadav, SEO Expert, Professional Blogger, Programmer, and UI Developer. Get a Solution of More Than 500+ Programming Problems, and Practice All Programs in C, C++, and Java Languages. Get a Competitive Website Solution also Ie. Hackerrank Solutions and Geeksforgeeks Solutions. If You Are Interested to Learn a C Programming Language and You Don't Have Experience in Any Programming, You Should Start with a C Programming Language, Read: List of Format Specifiers in C.
Follow Me

2 comments:

  1. #include
    #include
    int main()
    {
    mpz_t n1,n2,r,q;
    mpz_init(n1);
    mpz_init(n2);
    gmp_scanf("%zd\n",n1);
    gmp_scanf("%zd\n",n2);
    while(mpz_comp_ui(r,0))
    {
    mpz_cdiv_q(q1,n1,n2);
    mpz_
    }
    }

    ReplyDelete
  2. Please explain same program in java

    ReplyDelete