[Show all top banners]
Back to: Kurakani General Refresh page to view new replies
 c++
[VIEWED 4615 TIMES]
SAVE! for ease of future access.
Posted on 09-25-11 11:16 AM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

can anyone help me with permutation in c++ ?

 
Posted on 09-25-11 11:21 AM     [Snapshot: 1]     Reply [Subscribe]
Login in to Rate this Post:     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;
}

 
Posted on 09-25-11 3:55 PM     [Snapshot: 111]     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

 you can use dynamic memory allocation using "new"
 
Posted on 09-25-11 10:24 PM     [Snapshot: 205]     Reply [Subscribe]
Login in to Rate this Post:     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!

 
Posted on 09-25-11 11:57 PM     [Snapshot: 279]     Reply [Subscribe]
Login in to Rate this Post:     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 be able to reply! If you don't have a login, please register here.

YOU CAN ALSO



IN ORDER TO POST!




Within last 365 days
Recommended Popular Threads Controvertial Threads
Lets play Antakshari...........
डीभी परेन भने खुसि हुनु होस् ! अमेरिकामाधेरै का श्रीमती अर्कैसँग पोइला गएका छन् !
शीर्षक जे पनि हुन सक्छ।
What are your first memories of when Nepal Television Began?
[New post] Why Would Krishna Have To Run From The Battlefield
Sajha Poll: नेपालका सबैभन्दा आकर्षक महिला को हुन्?
ChatSansar.com Naya Nepal Chat
is Rato Bangala school cheating?
Why always Miss Nepal winner is Newari??
NRN card pros and cons?
Basnet or Basnyat ??
पुलिसनी संग - आज शनिवार - अन्तिम भाग
निगुरो थाहा छ ??
Nas and The Bokas: Coming to a Night Club near you
TPS Re-registration
श्राद्द
सेक्सी कविता - पार्ट २
What Happened to Dual Citizenship Bill
पाप न साप घोप्टो पारि थाप !!
अमेरिकामा छोरा हराएको सूचना
Nas and The Bokas: Coming to a Night Club near you
राजदरबार हत्या काण्ड बारे....
Mr. Dipak Gyawali-ji Talk is Cheap. US sends $ 200 million to Nepal every year.
Harvard Nepali Students Association Blame Israel for hamas terrorist attacks
TPS Update : Jajarkot earthquake
is Rato Bangala school cheating?
NOTE: The opinions here represent the opinions of the individual posters, and not of Sajha.com. It is not possible for sajha.com to monitor all the postings, since sajha.com merely seeks to provide a cyber location for discussing ideas and concerns related to Nepal and the Nepalis. Please send an email to admin@sajha.com using a valid email address if you want any posting to be considered for deletion. Your request will be handled on a one to one basis. Sajha.com is a service please don't abuse it. - Thanks.

Sajha.com Privacy Policy

Like us in Facebook!

↑ Back to Top
free counters