Saturday, 18 June 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


1 comment:
Write 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

Recommended Posts × +