Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
When I Enter 1 it should print A,E,I,O,U,Y and if 2 then output should be AA ,AE,AI,AO,AU,AY.....EA,EE,EI.....YY, it should generate till 20.

C++
#include <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
    
    char i;
    int result;
    cout<<"Enter Number\n";
    cin>>result;
        
           for (i ='A'; i <'Z'; i++)
           cout<<" "<<i;
    
    system("PAUSE");
    return 0;
}
Posted
Updated 26-Jan-10 21:17pm
v4

Generating all combinations up to 20 would take a REALLY long time to execute. Also, we are not here to do your work/homework/interview questions for you. Let us know what specific problems you are having with what you've tried so far and we may be able to help you.
 
Share this answer
 
For better or worse, here is your solution (a partial solution, which only prints the combinations for exactly 20 vowels, and which is written in C#):
} ;)(gnirtSoT.onhceTdaBgnortS nruter } ;))knidrepmuHtrebelgnI(eheheH(dneppA.onhceTdaBgnortS { )detraFgodrednU ni knidrepmuHtrebelgnI margoloH( hcaerof ;)htgneL.detraFgodrednU(niugnePAnOkcuDA wen = onhceTdaBgnortS niugnePAnOkcuDA { )detraFgodrednU ][margoloH(erocdraHtItaE tneidarGionoroV citats cilbup } ;]mun[staCfOsderdnuH nruter { )mun margoloH(eheheH tneidarGionoroV citats cilbup ;} "Y" ,"U" ,"O" ,"I" ,"E" ,"A" { = staCfOsderdnuH ][tneidarGionoroV citats etavirp } } } ;kaerb { )sgnihTetirovaFyMfOemoSerAesehT( fi } } ;kaerb ;eslaf = sgnihTetirovaFyMfOemoSerAesehT { )5 < i( fi { )srekcauq ni i margoloH( hcaerof ;eurt = sgnihTetirovaFyMfOemoSerAesehT regrubseehCsaHnortageM ;)"," + )srekcauq(erocdraHtItaE(etirW.tuO.elosnoC.metsyS ;)rekcitSrepmub( elihw } } ;eslaf = rekcitSrepmub { esle } ;--xeHnogard ;eurt = rekcitSrepmub ;0 = ]xeHnogard[srekcauq { )5 > ]xeHnogard[srekcauq( fi ;1 + ]xeHnogard[srekcauq = ]xeHnogard[srekcauq { od ;91 = xeHnogard margoloH ;eslaf = rekcitSrepmub regrubseehCsaHnortageM { )eurt( elihw } ;0 = ]sreppey[srekcauq { )++sreppey ;02 < sreppey ;0 = sreppey margoloH( rof ;]02[margoloH wen = srekcauq ][margoloH { )sgra ][tneidarGionoroV(niaM diov citats

Note that I have reversed all of the code. I have also removed all newline characters and tabs and replaced them with spaces. Also, I used "using NewName = OldNamespace.Oldtype;" to rename all types to a type that is completely unrecognizable (and I didn't include those "usings" in the above code). If you can decipher that code, you have used some problem solving abilities and I am convinced that you will then deserve the solution. I'm sure you can... you just need to decide which route you want to take: solve the problem yourself, or use my solution by deciphering the above code. Happy coding :)
 
Share this answer
 
v2
This is a modest task for you to get started with. If you have problems when you are working on it and have tried to solve them yourself, you might post what you have done and what the problem is that you encountered. At that time someone may be able to help you.

You can start by getting the entry(you've already written this) and checking that it is valid. Next you have to figure out how to do the job. There are 2 parts to this - generating all the possibilities and producing the output. I can think of 2 basic approaches to this, one is using a loop and the other is recursive. Since you haven't indicted anything about how you plan to do this, I can't really help you any further. This is your homework. You'll have to think about how to accomplish the task, come up with a plan, and start in on it. Once you have started on your homework, you may seek help on problems you encounter in your efforts.
 
Share this answer
 
v2
 
Share this answer
 
Naveen, the link you posted will not help the asker. next_permutation does not show all combinations of N items for X digits. It only shows all combinations of N items for N digits (i.e., the number of digits and the number of items are always equal) and without repeats (i.e., "AA" wouldn't be allowed because "A" is used twice).
 
Share this answer
 
v3
shouldn't be hard to convert ;P

Java
public class Test
{
    public static void main(String[] args)
    {
        String[] vowels = {"A","E","I","O","U"};
        String output [] = result(3,vowels);
        
        for (int i =0; i < output.length; i++)
            System.out.print(output[i] + " ");
    }
    
    public static String[] result (int count,String [] vowels)
    {
        int k = 0,j = 0;
        String temp[] = new String[count*vowels.length];
        for (int i = 0; i < count; i++)
        {
            for (int h = 0; h < vowels.length; h++)
            {
            temp[j]=vowels[k]+vowels[h];
            j++;    
            }
        k++;
        }
        return temp;
    
    }
}
 
Share this answer
 
C++
#include <stdio.h>
void step(char out[], int level, int depth)
{
  static const char data[]="AEIOUY";
  const int SIZE= sizeof(data)/sizeof(data[0])-1;
  for (int i=0; i<SIZE; i++)
  {
    out[level]=data[i];
    if( level==depth-1) 
      printf("%s\n",out);
    else
      step(out, level+1, depth);
  }
}
int  main()
{
  int depth = 0;
  do
  {
    printf("Please insert sequence length\n");
    if (scanf("%d", &depth) != 1)
      depth=0;
  } while ( depth < 1 || depth > 20);
   
  char * out = new char[depth+1];
  memset(out, 0, depth+1);
  step(out, 0, depth);
  delete [] out;
  return 0;
}


:)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900