Untitled

mail@pastecode.io avatar
unknown
plain_text
3 years ago
1.7 kB
1
Indexable
Never
#include <stdio.h>
#include <stdlib.h>

void insertionSort(int * arr, int n){
	int i, j, temp;
	for(i = 1;i<n;i++){
		for(j = i;j>0;j--){
			if(arr[j] < arr[j-1]){
				temp = arr[j];
				arr[j] = arr[j-1];
				arr[j-1] = temp;	
			}else break;
		}
	}
}

int kolonSayisiOku(){
	int n;
	printf("Kac kolon oynanacagini giriniz: ");
	scanf("%d", &n);
	
	while(n < 1 && n > 10){
		printf("Kolon sayisi araligi yalnizca 1-10 araliginda olmalidir.\n");
		printf("Tekrar giris yapiniz: ");
		scanf("%d", &n);
	}
	return n;
}

int kolonGecerliMi(int * kolon){
	int ciftler		 = 0,
		tekbasamakli = 0,
		ardisik 	 = 0;
		
	insertionSort(kolon, 6);
	int i;
	for(i = 0;i<6;i++){
		if(i != 0){
			if(kolon[i] == kolon[i-1]){
				return 0;
			}
			if(kolon[i] == kolon[i-1] + 1)
				ardisik++;	
		}
		
		if(kolon[i] % 2 == 0)
			ciftler++;
			
		if(kolon[i] < 10)
			tekbasamakli++;
	}
	
	if(ciftler < 2 || ciftler > 4 || tekbasamakli > 2 || ardisik > 2)
		return 0;
	return 1;
}

int main(){
	srand(time(NULL));
	FILE * fp = fopen("kolon.txt", "w");
	
	int n = kolonSayisiOku();
	int i, j;
	
	int tahmin[n][6];
	for(i = 0;i<n;i++){
		for(j = 0;j<6;j++)
			tahmin[i][j] = rand() % 50 + 1;
		
		while(!kolonGecerliMi(tahmin[i]))
			for(j = 0;j<6;j++)
				tahmin[i][j] = rand() % 50 + 1;
	}
	
	/* 2
		1 2 20 15 13 26
		14 9 35 34 28 30
	*/
	printf("\n");
	printf("Girilen tum kolonlar: \n");
	fprintf(fp, "Girilen tum kolonlar: \n");
	for(i = 0;i<n;i++){
		for(j = 0;j<6;j++){
			printf("%3d ",tahmin[i][j]);
			fprintf(fp, "%3d ",tahmin[i][j]);
		}
		printf("\n");
		fprintf(fp, "\n");
	}

	return 0;
}