
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
C++ Program to Generate N Number of Passwords of Length M Each
This is a C++ Program to Generate N Number of Passwords of Length M Each.
Algorithm
Begin Take the length of password as input. function permutation() generate random passwords: /* Arguments A pointer array a. Total Number of random numbers m. Length of the password s. */ // Body of the function: if (m == s) for i = 0 to s-1 Print *(a + i) else for i = m to s-1 int tmp = a[m] a[m] = a[i] a[i] = tmp Call permutation(a, m + 1, s) tmp = a[m] a[m] = a[i] a[i] = tmp End
Example
#include<iostream> #include<conio.h> #include<stdlib.h> using namespace std; void permutation(int *a, int m, int s) { if (m == s) { for (int i = 0; i < s; i++) { cout << *(a + i); } cout << endl; } else { for (int i = m; i < s; i++) { int tmp = a[m]; a[m] = a[i]; a[i] = tmp; permutation(a, m + 1, s); tmp = a[m]; a[m] = a[i]; a[i] = tmp; } } } int main(int argc, char **argv) { cout << "Enter the length of the password: "; int n; cin >> n; int a[n]; for (int i = 0; i < n; i++) { a[i] = rand() % 10; //randomly generate numbers } cout <<"Random Numbers are:" <<endl; for (int i = 0; i < n; i++) { cout<<a[i] <<endl; } cout << "The Passwords are: "<<endl; permutation(a, 0, n); }
Output
Enter the length of the password: 4 Random Numbers are: 1740T he Passwords are: 1740 1704 1470 1407 1047 1074 7140 7104 7410 7401 7041 7014 4710 4701 4170 4107 4017 4071 0741 0714 0471 0417 0147 0174
- Related Articles
- C++ program to generate random number
- How to generate passwords with varying lengths in R?
- 8086 program to generate AP series of n numbers
- 8086 program to generate G.P. series of n numbers
- C program to generate the value of x power n using recursive function
- How to Automatically Generate Random Secure Passwords in Google Chrome?
- C# Program to Generate Marksheet of Student
- JavaScript Program to Generate all rotations of a number
- C++ Program to Generate a Sequence of N Characters for a Given Specific Case
- Convert a number m to n using minimum number of given operations in C++
- Program to compare m^n and n^m
- C++ program to count number of stairways and number of steps in each stairways
- Program to find remainder after dividing n number of 1s by m in Python
- C++ Program to Generate a Random UnDirected Graph for a Given Number of Edges
- Find the minimum number of steps to reach M from N in C++

Advertisements