Created
January 21, 2021 22:59
-
-
Save pcnoic/7c1b84c8db9e3205d922d58d86c5d1fd to your computer and use it in GitHub Desktop.
code that will save your live
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
int *read(int); | |
int oria(int,int); | |
int readx(); | |
int ready(); | |
int oriay(int,int); | |
void printc(int *); | |
int poscomb(int); | |
int *combArray(int,int*, int); | |
void print(int*,int); | |
int main(int argc, char **argv) | |
{ | |
system ("chcp 1253"); | |
int c = 1,*A,N,X1,X2,flag,Y1,Y2,flagy,i,pcomb; | |
//c = convertToString(c);// | |
do{ | |
printf("Πόσους αριθμούς θέλετε να εισάγετε; \nN = "); | |
scanf ("%d",&N); | |
}while (N <= 6 || N >= 50 ); | |
A = read(N); | |
do | |
{ | |
X1 = readx(); | |
X2 = readx(); | |
flag = oria(X1,X2); | |
if (flag == 1) | |
printf ("Τα όρια δεν είναι σωστά παρακαλώ εισάγετε ξανά τα Χ\n"); | |
}while (flag == 1); | |
do | |
{ | |
Y1 = ready(); | |
Y2 = ready(); | |
flagy = oriay(Y1,Y2); | |
if (flagy == 1) | |
printf ("Τα όρια δεν είναι σωστά παρακαλώ εισάγετε ξανά τα Y\n"); | |
}while (flagy == 1); | |
pcomb = poscomb(N); | |
combArray(N,A,pcomb); | |
return 0; | |
} | |
int *read(int N) | |
{ | |
int *A,i,num; | |
A = (int*) malloc(N); | |
printf("enter %d elements \n", N); | |
for (i = 0; i < N; i++){ | |
scanf("%d", &A[i]); | |
} | |
return A; | |
} | |
int readx() | |
{ | |
int x; | |
do | |
{ | |
printf("Δώστε τιμή για το X: "); | |
scanf("%d",&x); | |
if (x < 0 || x > 6) | |
printf ("Το X πρέπει να ανήκει στο διάστημα 0 έως 6!\n"); | |
}while (x <= -1 || x >= 7); | |
return x; | |
} | |
int oria(int a,int b) | |
{ | |
if (a < b) | |
return 0; | |
else | |
return 1; | |
} | |
int ready() | |
{ | |
int y; | |
do | |
{ | |
printf("Δώστε τιμή για το Y: "); | |
scanf("%d",&y); | |
if (y <= 20 || y >= 280) | |
printf ("Το Y πρέπει να ανήκει στο διάστημα 21 έως 279!\n"); | |
}while (y <= 20 || y >= 280); | |
return y; | |
} | |
int oriay(int a,int b) | |
{ | |
if (a >= 21 && b >= 21 && a <= b && b <= 279) | |
return 0; | |
else | |
return 1; | |
} | |
int poscomb(int N) | |
{ | |
int comb,i,s = 1,diaf; | |
for (i = 1; i <= N; i++) | |
s = s * i; | |
diaf = N - 6; | |
comb = s / (720 * diaf); | |
return comb; | |
} | |
int *combArray(int N,int A[], int multiplierConstant) | |
{ | |
int i, tempVar; | |
int largeArrayLim = N* (multiplierConstant - 1); | |
int temp[largeArrayLim], tempResult[6]; | |
int breaker = 0; | |
for (i = 0; i < largeArrayLim; i++){ | |
if (breaker == 7){ | |
breaker = 0; | |
} | |
temp[i] = A[breaker]; | |
breaker++; | |
} | |
//make function that checks requirements for arrays, if they're not ok, discard array | |
// make this a function and use it on every array you can create - sorting | |
for (i = 0; i < 6; i++) { | |
tempResult[i] = temp[i]; | |
for (int j = 0; j < 6; j++) { | |
for (int k = k + 1; k < 6; k++) { | |
if (tempResult[j] > tempResult[k]) { | |
tempVar = tempResult[j]; | |
tempResult[j] = tempResult[k]; | |
tempResult[k] = tempVar; | |
} | |
} | |
} | |
} | |
// for debugging puproses - printing on console | |
for (i = 0; i < largeArrayLim; i++) | |
{ | |
printf("%d",temp[i]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment