Write a C++ program that generates a sequence of 26 random letters, without duplication, one letter per output line.
#include <iostream> #include <cstdlib> #include <ctime> using namespace std; int main(){ char arr[26], ch; int found, k = 0; srand((unsigned)time(NULL)); for(int i = 0;k<26;i++){ ch = 'a' + (rand()%26); found = 0; for(int j = 0;j<k;j++){ if(arr[j]==ch){ found = 1; break; } } if(found == 0){ arr[k++] = ch; } } for(int i = 0;i<26;i++){ cout<<arr[i]<<" "; } return 0; }
Get Answers For Free
Most questions answered within 1 hours.