Results 1 to 5 of 5

Thread: Code for Permutations

  1. #1
    Join Date
    Mar 2010
    Posts
    732

    Code for Permutations

    Hey Guys, I wanted to know the code for Permutations. I don’t mind it whether it may be in any language. If anyone knowing about the code for permutation then please let me know as I wanted it very urgently. As, I said that code can be in any programming language such as C. C++, Java, C# etc… So, please let me know as I am eagerly waiting for the reply.

  2. #2
    Join Date
    May 2009
    Posts
    511

    Re: Code for Permutations

    Code:
    #include <string>
    #include <iostream>
    
    using namespace std;
    
    void string_permutation( std::string& original, std::string& permutation )
    {
        if( original.empty() )
        {
            std::cout<<permutation<<std::endl;
            return;
        }
    
        for(int i=0;i<original.size();++i)
        {
            std::string orig2 = orig;
    
            orig2.erase(i,1);
    
            std::string perm2 = permutation;
    
            perm2 += original.at(i);
    
            string_permutation(orig2,perm2);
        } 
    }
    
    int main()
    {
        std::string orig="QWERT";
        std::string perm;  
    
        string_permutation(original,permutation);
    
        cout<<"Done!"<<endl;
    
        system("Stop");
    
        return 0;
    }
    This is an code for Permutations in C++. This will enable you to get the appropriate result. You need to run this code in Turbo C which will give you the appropriate result.

  3. #3
    Join Date
    Mar 2010
    Posts
    732

    Re: Code for Permutations

    Hey thank you I got the result but know I wanted the code for factorial which I have got as assignment in my college. So, please if you have code for permutation and some simple program in C++ then please help me out. If you are having then please post it so that I could submit this assignment. So, please help me out.

  4. #4
    Join Date
    May 2009
    Posts
    637

    Re: Code for Permutations

    This is the Program to find factorial of number which is C++ code. I think that this is the most simplest code in C++.

    Code:
    #include<iostream.h>
    #include<conio.h>
    main()
    {
        int i,m,fact=1;
        clrscr();
        cout<<”Enter a positive number”;
        cin>>m
         for(i=1;i<=m;++i)
               fact=fact*I;
         cout<<”factorial of given number is   ” << fact;
     }

  5. #5
    Join Date
    Apr 2009
    Posts
    488

    Re: Code for Permutations

    This the Program for generation of Fibonacci series 1 1 2 3 5 8 13……. Which is mostly are unable to solve. Thought it seems simple but when you think and code it, its very difficult. I think that you need to have a good technique for coding any program so that you could make it more simple and short.

    Code:
    #include<iostream.h>
    #include<conio.h>
    main()
    {
       int f0 ,f1,f2,i,n;
       cout<<”Enter a  number “;
        cin>>n;
        f0=f1=1;
        cout<< f0 <<”   “<<f1<<”  “;
        for(i=2;i<=n;++i)
             {
              f2=f0+f1;
              cout<<f2<<”   “;
              f0=f1;
              f1=f2;
             }
    }

Similar Threads

  1. Replies: 15
    Last Post: 02-05-2014, 03:00 PM
  2. startup error code:0x80090006 ,,unable to locate activation code
    By Mr.Walter in forum Windows XP Support
    Replies: 3
    Last Post: 04-01-2012, 06:08 PM
  3. Replies: 5
    Last Post: 08-07-2011, 07:53 PM
  4. How to perform permutations in c++
    By Linoo in forum Software Development
    Replies: 4
    Last Post: 09-02-2010, 07:37 PM
  5. Permutations help in php
    By HardWeaR in forum Software Development
    Replies: 3
    Last Post: 02-12-2009, 02:35 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,520,705.40095 seconds with 17 queries