Merhabalar Harf isimli 5x10 boyutlu elemanları ingilizce bir büyük ve bir küçük olacak şekilde harflerden (A’dan Z’ye ve a’dan z’ye) rasgele oluşan bir matris oluşturmam lazım. Resimdeki gibi gözükmesi lazım Harf sadece bir kere kullanılması lazım. Matris 5x10 olması lazım. C++ ![]() |
C++ ile Harf Matrisi Oluşturma.


-
-
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<time.h>
#define MIN_B 65
#define MAX_B 90
#define MIN_S 97
#define MAX_S 122
#define ROW 5
#define COLUMN 10
int isLetterUsed(char letter, char usedLetters[]) {
for(int i=0;i<ROW*COLUMN;i++) {
if(letter == usedLetters[i])
return 1;
}
return 0;
}
void fillLetters(char letters[][COLUMN]) {
char letter = MIN_B;
char tempLetters[ROW*COLUMN];
int count = 0;
while(1) {
if(count >= ROW*COLUMN)
break;
if(count%2 == 0) {
char letterBig = (rand() % (MAX_B - MIN_B + 1)) + MIN_B;
if(isLetterUsed(letterBig, tempLetters))
continue;
tempLetters[count] = letterBig;
}
else {
char letterSmall = (rand()%(MAX_S - MIN_S + 1)) + MIN_S;
if(isLetterUsed(letterSmall, tempLetters))
continue;
tempLetters[count] = letterSmall;
}
count++;
}
count = 0;
for(int i=0;i<ROW;i++) {
for(int j=0;j<COLUMN;j++) {
letters[i][j] = tempLetters[count++];
}
}
}
void printLetters(char letters[][COLUMN]) {
for(int i=0;i<ROW;i++) {
for(int j=0;j<COLUMN;j++) {
printf("%c ", letters[i][j]);
}
printf("\n");
}
}
void sortLetters(char letters[][COLUMN]) {
char tempLetters[ROW*COLUMN];
int index = 0;
for(int i=0;i<ROW;i++) {
for(int j=0;j<COLUMN;j++) {
tempLetters[index++] = letters[i][j];
}
}
int small = 0;
for(int i=0;i<ROW*COLUMN;i++) {
small = i;
for(int j=i;j<ROW*COLUMN;j++) {
if(tempLetters[small] > tempLetters[j])
small = j;
}
char temp = tempLetters[small];
tempLetters[small] = tempLetters[i];
tempLetters[i] = temp;
}
index = 0;
for(int i=0;i<ROW;i++) {
for(int j=0;j<COLUMN;j++) {
letters[i][j] = tempLetters[index++];
}
}
}
void main(int argc, char **argv) {
srand(time(NULL));
char letters[ROW][COLUMN];
fillLetters(letters);
printf("First state : \n");
printLetters(letters);
sortLetters(letters);
printf("Last state : \n");
printLetters(letters);
}
-
quote:
Orijinalden alıntı: Mr.Tiger#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<time.h>
#define MIN_B 65
#define MAX_B 90
#define MIN_S 97
#define MAX_S 122
#define ROW 5
#define COLUMN 10
int isLetterUsed(char letter, char usedLetters[]) {
for(int i=0;i<ROW*COLUMN;i++) {
if(letter == usedLetters[i])
return 1;
}
return 0;
}
void fillLetters(char letters[][COLUMN]) {
char letter = MIN_B;
char tempLetters[ROW*COLUMN];
int count = 0;
while(1) {
if(count >= ROW*COLUMN)
break;
if(count%2 == 0) {
char letterBig = (rand() % (MAX_B - MIN_B + 1)) + MIN_B;
if(isLetterUsed(letterBig, tempLetters))
continue;
tempLetters[count] = letterBig;
}
else {
char letterSmall = (rand()%(MAX_S - MIN_S + 1)) + MIN_S;
if(isLetterUsed(letterSmall, tempLetters))
continue;
tempLetters[count] = letterSmall;
}
count++;
}
count = 0;
for(int i=0;i<ROW;i++) {
for(int j=0;j<COLUMN;j++) {
letters[i][j] = tempLetters[count++];
}
}
}
void printLetters(char letters[][COLUMN]) {
for(int i=0;i<ROW;i++) {
for(int j=0;j<COLUMN;j++) {
printf("%c ", letters[i][j]);
}
printf("\n");
}
}
void sortLetters(char letters[][COLUMN]) {
char tempLetters[ROW*COLUMN];
int index = 0;
for(int i=0;i<ROW;i++) {
for(int j=0;j<COLUMN;j++) {
tempLetters[index++] = letters[i][j];
}
}
int small = 0;
for(int i=0;i<ROW*COLUMN;i++) {
small = i;
for(int j=i;j<ROW*COLUMN;j++) {
if(tempLetters[small] > tempLetters[j])
small = j;
}
char temp = tempLetters[small];
tempLetters[small] = tempLetters[i];
tempLetters[i] = temp;
}
index = 0;
for(int i=0;i<ROW;i++) {
for(int j=0;j<COLUMN;j++) {
letters[i][j] = tempLetters[index++];
}
}
}
void main(int argc, char **argv) {
srand(time(NULL));
char letters[ROW][COLUMN];
fillLetters(letters);
printf("First state : \n");
printLetters(letters);
sortLetters(letters);
printf("Last state : \n");
printLetters(letters);
}
Eyvallah Reis C++ az bilgim var ama takılı kalmıştım biryerde teşekkürler yardımcı olduğun için
-
Rica ederim. =)
< Bu ileti Android uygulamasından atıldı >
Bu mesaj IP'si ile atılan mesajları ara Bu kullanıcının son IP'si ile atılan mesajları ara Bu mesaj IP'si ile kullanıcı ara Bu kullanıcının son IP'si ile kullanıcı ara
KAPAT X