ERGASTHRIO 8

Synarthseis

1.

/*Erg8_1.c : Kataskeyh synarthshs ypologismou ypervolikou hmitonou
* Eisagwgh dedomenwn mesw synarthshs
*
* PROSOXH STO LOGIKO VROGXO while POU EPANALAMVANEI THN EISAGWGH
* DEDOMENWN MEXRI NA STAMATHSEI ME 0 */

#include <stdio.h>
#include <math.h>

double my_sinh(double x1);
void read_input(double *x2);

int main(void)
{
int n=1; /*Akeraios deikths pou xrhsimopoieitai gia na stamathsei
o vrogxos while otan to n ginei 0*/
double x, z1, z2;

printf("YPOLOGISMOS TOY YPERVOLIKOY HMITONOY\n");

while(n) /*Logikos vrogxos while*/
{
read_input(&x);
z1 = my_sinh(x);
z2=sinh(x);
printf("----------------------------------------\n");
printf(" sinh(%lf)\n", x);
printf("Ypervoliko\tYpervoliko\n");
printf("Hmitono\t\tHmitono\n");
printf("mesw C\t\tme dikia mou\n");
printf(" \t\tsynarthsh\n");
printf("%-10.5lf\t%-10.5lf\n\n\n", z1, z2);

printf("Thelete na ypologisete kai "
"gia allh timh tou x\?"
" Ean nai, plhktrologhste 1,"
" gia eksodo plhktrologhste 0\n");
scanf("%d",&n);
/*Ean n=0 tote automata vgainoume apo ton vrogxo while*/
printf("\n\n");
}

return 0;
}


double my_sinh(double x1)
{
double my_sinh1;

my_sinh1 = ( exp(x1)-exp(-x1) )/2.0;
return (my_sinh1);
}

void read_input(double *x2)
{
printf("Dwste to orisma gia ton ypologismo\n");
scanf("%lf",&*x2);
return;
}







2.

/*Erg8_2.c Askhsh ypologismou megistou metaksy 3 akeraiwn arithmwn
* Akeraia synarthsh max3 gia ypologismo megistou*/

#include <stdio.h>

int max3(int i, int j, int k);

int main(void)
{
int a, b, c, max_no;
printf("Dwste 3 akeraious arithmous\n");
scanf("%d %d %d", &a, &b, &c);
max_no = max3(a, b, c);
printf ("O megistos metaksy twn %d, %d, %d einai"
"o %d\n", a, b, c, max_no);
return 0;
}

int max3(int i, int j, int k)
{
int max;

if (i>j && i>k)
max = i;
else if (j>i && j>k)
max = j;
else if (k>i && k>j)
max = k;
else /*kapoioi einai isoi metaksy toys*/
{
if (i==j && i==k) /*oloi isoi metaksy tous*/
max = i;
else /*den einai oloi isoi metaksy tous, duo toulaxiston
omws einai */
{
if (i==j)
{
if (i>k)
max = i;
else
max = k;
}
else if (i==k)
{
if (i>j)
max = i;
else
max = j;
}
else /*h monadikh enapomeinousa peristwsh, j=k*/
{
if (i>k)
max = i;
else
max = k;
}
} /*telos elegxou periptwshs pou dyo apo toys treis einai isoi*/

} /*Telos elegxou periptwshs pou TOYLAXISTON 2 einai isoi metaksy tous */

return (max);
}