Nov 8, 2016 at 8:35pm UTC
I have found this program for combination. But i am havig "expected a decleration" error. what am i missing?
#include<iostream>
#include<algorithm>
using namespace std;
void perm(string s, string t);
{
if (s.lenght() == 0)
{
cout << t << endl;
return 0;
}
for (int i = 0, i < s.lenght(); i++);
{
string s2 = s;
string t2 = t;
s2.erase(i, 1);
t2 += s[i];
perm(s2, t2);
}
}
int main()
{
string s = "xyz";
string t;
perm(s, t);
return 0;
}
Errors;
expected a decleration line: 6
'{': missing function header (old-style formal list?) line :6
Nov 8, 2016 at 11:45pm UTC
Thank you it will help a lot.
Nov 9, 2016 at 8:26am UTC
Fixed without changing what you want the code to do:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
#include <iostream>
#include <algorithm>
using namespace std;
void perm(string s, string t)
{
if (s.length() == 0)
{
cout << t << endl;
}
else
{
for (int i = 0; i < s.length(); i++)
{
string s2 = s;
string t2 = t;
s2.erase(i, 1);
t2 += s[i];
perm(s2, t2);
}
}
}
int main()
{
string s = "xyz" ;
string t;
perm(s, t);
return 0;
}
Last edited on Nov 9, 2016 at 8:27am UTC