20 March, 2012

C++ Program For Generating Numbers In The Given Number's Combination.

This Post Contains A C++ Program For Generating Numbers In The Given Number's Combination With Correct Source Code & Output. This Program Is Written, Compiled & Executed At TurboC3.0 Compiler & Will Help You To Understand The Concept Of 'Arrays', 'For-loop', 'While-loop' & 'Nested Loops' From C++ Language. It Is A Well-Structured Program With Proper Comments Which Provides Step-By-Step Description Of Various Features Of The Language In A Simple & Easy-To-Understand Way.


# Note : You Can Simply Copy-Paste The Following Program Or Code Into Compiler For Direct Result.


C++ Program For Generating Numbers In The Given Number's Combination.

/* Declaration Of Header Files */

# include <iostream.h>
# include <conio.h>

/* Start Of Main Program */
void main()
{

   /* Declaration Of Variables */
   int   i,   j,   r,   s,   t,    d,   range;
   int p[ 5 ],   q[ 5 ];
   long  n;

   clrscr();

   /* Asking For The Input From User */
   cout << " Enter No. Of Numbers For Combination  :  ";
   cin >> d;
   cout << " Enter Nos. For Combination  :  ";
   for  (  i   =   0;   i   <   d;   i++  )
   {
           cin >> p[ i ];
   }
   cout << " Enter Range : ";
   cin >> range;
  
   /* Source Code For Generating Numbers In The Given Number's Combination */
   for  (  i   =   1;  i   <=   range;   i++   )
   {
             n   =    i;
             s   =   0;
             t   =   0;
     while(  n   >   0  )
     {
              j    =    0;
              r    =   n    %    10;
              t++ ;
             while  (  j    <    d  )
             {
                      if  (  r   ==   p[ j ]  )
                     {
                             s++ ;
                             j++ ;
                     }
             }
             n   =   n   /   10;
     }
     if  (  s   ==   t  )
            cout  <<   i   <<   "  \t  ";
  }
  getch();
}
/* End Of Main Program */ 

Output :

Enter No. Of Numbers For Combination : 2
Enter Nos. For Combination : 1  3
Enter Range : 1000
1  3  11  13  31  33  111   113   131   133  311 313  331  333      




No comments:

Post a Comment

Subscribe To:

Most Commonly Asked Programs In 'C' & 'C++' Language.