This C program generates N number of passwords, each of length M. This problem focuses on finding the N permutations each of length M.
Here is the source code of the C program to generate random passwords of equal length. The C program is successfully compiled and run on a Linux system. The program output is also shown below.
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
/* Length of the password */
int length;
int num;
int temp;
printf("Enter the length of the password: ");
scanf("%d", &length);
printf("\nEnter the number of passwords you want: ");
scanf("%d", &num);
/* Seed number for rand() */
srand((unsigned int) time(0) + getpid());
while(num--)
{
temp = length;
printf("\n");
while(temp--) {
putchar(rand() % 56 + 65);
srand(rand());
}
temp = length;
}
printf("\n");
return EXIT_SUCCESS;
}
$ gcc password.c -o password $ ./password Enter the length of the password: 8 Enter the number of passwords you want: 5 Yfqdpshp GZJqGuiB ^jFUTLOo WbNK]Teu ]wrQSBNY
Sanfoundry Global Education & Learning Series – 1000 C Programs.
advertisement
advertisement
Here’s the list of Best Books in C Programming, Data Structures and Algorithms.
Next Steps:
- Get Free Certificate of Merit in C Programming
- Participate in C Programming Certification Contest
- Become a Top Ranker in C Programming
- Take C Programming Tests
- Chapterwise Practice Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Chapterwise Mock Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
Related Posts:
- Practice BCA MCQs
- Buy Computer Science Books
- Apply for Computer Science Internship
- Apply for C Internship
- Buy C Books