c++ - Sajha Mobile
SAJHA MOBILE
c++
Posts 5 · Viewed 7081 · Go to Last Post
alece
· Snapshot 0
Like · Likedby · 0
can anyone help me with permutation in c++ ?
alece
· Snapshot 1
Like · Liked by · 0
this is how i did!! and it works too!!! but my professor doesnt want me to define a specific number like 5 i did in the program!!! and he doesnt want me to use the std library too!!!how can i make the user input any size of the number user wants!!!and he wants me to do using own algorithm and use swap and other methods!! help me if u can !!!



#include
#include
#include
#define s 5

using namespace std;

int main () {

cout << "Input "< int per[s];

for (int i=0; i {
cin>>per[i];
}
int size = sizeof per/sizeof(int);

(per,per+size);

do {
for (int i=0; i {
cout << per[i] << " ";
}
cout< } while ( next_permutation (per,per+size) );
return 0;
}
nikkkk
· Snapshot 111
Like · Liked by · 0
 you can use dynamic memory allocation using "new"
khai_k_khai_k
· Snapshot 205
Like · Liked by · 0
To dynamically allocate an array:
 
int n;
printf("Kati euta number: ");
scanf("%d", &n);
 
 
int * arr = (int *) malloc(n * sizeof(int));
for(int i=0;i<n;i++)
{
printf("\nNumber %d halnus: ",i+1);
scanf("%d",&arr[i]);
}
 
for(int i=0;i<n;i++)
{
printf("%d\t",arr[i]);
}
 
free(arr);

Your Prof. might want you to swap the elements in the array (in place). See http://www.cplusplus.com/reference/algorithm/swap/ for details on this function.
Good luck!
alece
· Snapshot 279
Like · Liked by · 0
khai bro!! m pretty sure he wont let me do that way too!!!! to be honest i dun even know what he is looking for!!he is kinda retarded!!5-6 choti method bata dekhaisakee!! kahile ke bhancha kahile k!! maile ta gave hope!! hahah!! swap method use garera sakina!! plus ajha aafnaii algorithm use garnu parne and std library use garan naapaune!! taauko dukhaisakyoo!!! thanks anyways!! keep coding!!
Please log in to reply to this post

You can also log in using your Facebook
View in Desktop
What people are reading
You might like these other discussions...
· Posts 16 · Viewed 4503 · Likes 3
· Posts 1 · Viewed 1237 · Likes 3
· Posts 1 · Viewed 984 · Likes 3
· Posts 8 · Viewed 2633 · Likes 3
· Posts 1 · Viewed 1018
· Posts 12 · Viewed 3451
· Posts 1 · Viewed 848
· Posts 8 · Viewed 2170
· Posts 19 · Viewed 2525
· Posts 1 · Viewed 994



Travel Partners
Travel House Nepal