You are on page 1of 9

// Endeiktiki Lysi tis Askisis 1.1 - Ak.

Etos 2020-2021

#include <stdio.h>

int main(void)
{
int apousies;
float A = 0.0, PR1, PR2, BE, TE, GR;

/* Diavasmsa dedomenwn apo xristi */


printf("Parakalw dwse ton arithmo apousiwn: ");
scanf("%d", &apousies);

printf("Parakalw dwse ton vathmo prwtis proodou: ");


scanf("%f", &PR1);

printf("Parakalw dwse ton vathmo deuteris proodou: ");


scanf("%f", &PR2);

printf("Parakalw dwse ton vathmo telikis eksetasis: ");


scanf("%f", &TE);

/* Ypologismos vathmou apo parousies


* i metavliti A einai arxikopoiimeni
* idi sto 0.0.
*/
if (apousies == 0)
A = 10.0;
else if (apousies == 1)
A = 5.0;

/* Ypologismos vathmou ergastiriwn */


BE = A*0.2 + PR1*0.4 + PR2*0.4;

/* Elegxos gia teliko vathmo ergastiriwn */


if (BE < 4.5)
{
printf("Apotyxia sta ergastiria!\n");
return 1;
}

/* Elegxos gia vathmo telikis eksetasis */


if (TE < 4.5)
{
printf("Apotyxia stin teliki eksetasi!\n");
return 1;
}

/* Ypologismos telikou vathmou mathimatos */


GR = BE*0.5 + TE*0.5;

/* Ektypwsi apotelesmatos */
printf("Epityxia sto MYY502 me vathmo %.2f\n", GR);

return 0;
}
// Endeiktiki Lysi tis Askisis 1.2 - Ak. Etos 2020-2021

#include <stdio.h>

int main(void)
{
char chr, small;
int i, pos, given_letts = 0, given_digs = 0;
int nums[30];

do
{
printf("Dwste charaktira: ");
scanf(" %c", &chr);

/* Elegxoume an einai kefalaio gramma */


if (chr >= 'A' && chr <= 'Z')
{
/* Gia na paroume to mikro enos kefalaiou
grammatos arkei
* na vroume ti thesi toy sto alfavito (- 'A')
kai na tin prosthetoume
* sto mikro 'a'.
*/
small = (chr - 'A') + 'a';
printf("To mikro tou '%c' einai '%c'\n", chr,
small);
}
/* Elegxoume an einai mikro gramma */
else if (chr >= 'a' && chr <= 'z')
{
/* Gia na vroume tin thesi tou sto alfavito
afairoume ton
* ASCII tou "a", wste na vroume tin apostasi
tou apo ton
* charaktira a kai sti synexeia prosthetoume
1 giati px.
* to a einai o prwtos kai oxi o midenikos
xaraktiras.
*/
pos = (chr - 'a') + 1;
printf("To '%c' einai to %do gramma tou
agglikou alfavitou\n", chr, pos);
}
/* Elegxoume an einai noumero */
else if (chr >= '0' && chr <= '9')
{
/* Sthn periptwsi pou einai noumero tote
apothikeuoume ston
* pinaka nums tin aksia pou tha eixe an itan
akeraios.
* Gia na vroume tin aksia tou arkei na
afairesoume ton
* kwdiko ASCII tou xaraktira 0 (dhl. to '0').
*/
nums[given_digs++] = chr - '0';
}
/* Otidipote allo to ektypwnoume ws exei */
else
{
printf("Dwsate ton charactira '%c'\n", chr);
}

given_letts++;

}
while (chr != '$' && given_letts < 30);

printf("Arithmoi: ");
for(i=0; i<given_digs; i++)
printf("%d ", nums[i]);
printf("\n");

return 0;
}
// Endeiktiki Lysi tis Askisis 1.3 - Ak. Etos 2020-2021

#include <stdio.h>

/*Paradeigma apodektis lyshs sudoku*/


int M[9][9] = {{5,3,4,6,7,8,9,1,2},
{6,7,2,1,9,5,3,4,8},
{1,9,8,3,4,2,5,6,7},
{8,5,9,7,6,1,4,2,3},
{4,2,6,8,5,3,7,9,1},
{7,1,3,9,2,4,8,5,6},
{9,6,1,5,3,7,2,8,4},
{2,8,7,4,1,9,6,3,5},
{3,4,5,2,8,6,1,7,9}};

/*Paradeigma mh apodektis lyshs sudoku


int M[9][9] = {{5,3,4,6,7,8,9,1,2},
{5,7,2,1,9,5,3,4,8},
{1,9,8,3,4,2,5,6,7},
{8,5,9,7,6,1,4,2,3},
{4,2,6,8,5,3,7,9,1},
{7,1,3,9,2,4,8,5,6},
{9,6,1,5,3,7,2,8,4},
{2,8,7,4,1,9,6,3,5},
{3,4,5,2,8,6,1,7,9}};
*/

int main(void)
{
int check_solution(int matrix[9][9]);

if (check_solution(M) == 0)
printf("H lysh einai egkyrh\n");
else
printf("H lysh den einai egkyrh\n");
return 0;
}

int check_solution(int matrix[9][9])


{
int temp[10], i, j, k, l;

/* Elegxoyme ton pinaka ws pros kathe grammh.


* Den prepei na emfanizetai enas arithmos panw apo 1 fora
*/
for (j=0; j<9; j++)
{
for (i=0; i<10; i++)
temp[i] = 0;

for (i=0; i<9; i++)


{
if (temp[matrix[j][i]] >= 1)
return 1;
else
temp[matrix[j][i]]++;
}
}
/* Elegxoyme ton pinaka ws pros kathe sthlh.
* Den prepei na emfanizetai enas arithmos panw apo 1 fora
*/
for (j=0; j<9; j++)
{
for (i=0; i<10; i++)
temp[i] = 0;

for (i=0; i<9; i++)


{
if (temp[matrix[i][j]] >= 1)
return 1;
else
temp[matrix[i][j]]++;
}
}

/* Elegxoyme ton pinaka ws pros kathe 3x3 ypopinaka.


* Den prepei na emfanizetai enas arithmos panw apo 1 fora
*/
for (l=0; l<3; l++)
{
for (k=0; k<3; k++)
{
for (i=0; i<10; i++)
temp[i] = 0;

for (j=0; j<3; j++)


{
for (i=0; i<3; i++)
{
if (temp[matrix[j+3*l][i+3*k]]
>= 1)
return 1;
else

temp[matrix[j+3*l][i+3*k]]++;
}
}
}
}

return 0;
}
// Endeiktiki Lysi tis Askisis 1.4 - Ak. Etos 2020-2021

#include <stdio.h>

/* Paradeigma mh apodekths lyshs diagonal Sudoku


int M[9][9] = {{5,3,4,6,7,8,9,1,2},
{6,7,2,1,9,5,3,4,8},
{1,9,8,3,4,2,5,6,7},
{8,5,9,7,6,1,4,2,3},
{4,2,6,8,5,3,7,9,1},
{7,1,3,9,2,4,8,5,6},
{9,6,1,5,3,7,2,8,4},
{2,8,7,4,1,9,6,3,5},
{3,4,5,2,8,6,1,7,9}};
*/
/* Paradeigma apodekths lyshs diagonal Sudoku */
int M[9][9] = {{5,8,1,4,2,7,6,9,3},
{3,7,4,5,9,6,8,1,2},
{9,6,2,1,3,8,4,7,5},
{6,2,9,3,8,5,7,4,1},
{1,5,7,9,6,4,3,2,8},
{8,4,3,2,7,1,5,6,9},
{4,1,8,7,5,2,9,3,6},
{2,9,5,6,4,3,1,8,7},
{7,3,6,8,1,9,2,5,4}};

int main(void)
{
int check_solution(int matrix[9][9]);

if (check_solution(M) == 0)
printf("H lysh einai egkyrh\n");
else
printf("H lysh den einai egkyrh\n");

return 0;
}

int check_solution(int matrix[9][9])


{
int temp[10], i, j, k, l;

/* Elegxos tou pinaka ws pros kathe grammh - prwtos


periorismos */
for (j=0; j<9; j++)
{
for (i=0; i<10; i++)
temp[i] = 0;

for (i=0; i<9; i++)


{
if (temp[matrix[j][i]] >= 1)
return 1;
else
temp[matrix[j][i]]++;
}
}

/* Elegxos tou pinaka ws pros kathe sthlh - deuteros


periorismos */
for (j=0; j<9; j++)
{
for (i=0; i<10; i++)
temp[i] = 0;

for (i=0; i<9; i++)


{
if (temp[matrix[i][j]] >= 1)
return 1;
else
temp[matrix[i][j]]++;
}
}

/* Elegxos twn 3x3 pinakwn - tritos periorismos */


for (l=0; l<3; l++)
{
for (k=0; k<3; k++)
{
for (i=0; i<10; i++)
temp[i] = 0;

for (j=0; j<3; j++)


{
for (i=0; i<3; i++)
{
if (temp[matrix[j+3*l][i+3*k]]
>= 1)
return 1;
else

temp[matrix[j+3*l][i+3*k]]++;
}
}
}
}

/* Elegxos tou pinaka ws pros tis diagwnious */

// First diagonal
for (i=0; i<10; i++)
temp[i] = 0;

for (j=0; j<9; j++)


{
if (temp[matrix[j][j]] == 0)
temp[matrix[j][j]]++;
else
return 1;
}

// Second diagonal
for (i=0; i<10; i++)
temp[i] = 0;

for (j=0; j<9; j++)


{
if (temp[matrix[j][8-j]] == 0)
temp[matrix[j][8-j]]++;
else
return 1;
}
return 0;
}
// Endeiktiki Lysi tis Askisis 1.5 - Ak. Etos 2020-2021

#include <stdio.h>

void printbin(unsigned int num)


{
int digits[32];
int i, ndig = 0; /* Number of digits */

if (num == 0) /* Special case */


printf("0");

while (num != 0)
{
digits[ndig] = num % 2;
num = num / 2;
ndig++;
}

for (i = ndig-1; i >= 0; i--) /* Print in correct order */


printf("%d", digits[i]);
printf("\n");
}

int main(void)
{
unsigned int n;

do
{
printf("Enter a number (502 stops the program): ");
scanf("%d", &n);

if(n == 502)
break;

printbin(n);
}
while (1);

return 0;
}

You might also like