Answer to Question #244510 in C for Vipul

Question #244510

write a algorithm to reversethe required elements of password to get the actual password,so that file can be opened


1
Expert's answer
2021-09-29T18:44:19-0400
#include <stdio.h>  
#include <string.h>  

void generatePermutation(char * , int , int );  
  
int main() {  
  char str[] = "password"; // your characters
  int n = strlen(str);  
  printf("All the permutations of the string are: \n");  
  generatePermutation(str,0,n);  
  return 0;
}

void generatePermutation(char *str, const int start, int end) {  
  char temp;  
  for(int i = start; i < end-1; ++i){  
    for(int j = i+1; j < end; ++j) {  
      temp = str[i];  
      str[i] = str[j];  
      str[j] = temp;  
      generatePermutation(str , i+1 ,end);  
      temp = str[i];  
      str[i] = str[j];  
      str[j] = temp;  
    }  
  }    
  printf("%s\n",str);  
}  

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS