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