ERGASTHRIO
6
Paradeigma 1
Logikh praksewn, telestes suntheths anatheshs
Programma metatrophs vathmwn Kelsiou se Farenait apo 0C ws 100C ana 20C
/*Erg6_1.c Programma metatrophs vathmwn Kelsiou se Farenait*/
#include <stdio.h>
main()
{
double DegC, DegF;
printf("Pinakas Vathmwn Kelsiou se Farenait\n"
"Vathmoi\tVathmoi\n"
"Kelsiou\tFarenait\n");
DegC=0.0; /*Arxikh timh gia DegC*/
DegF=DegC*9.0/5.0 + 32.0;
printf("%6.2lf\t%6.2lf\n", DegC, DegF);
/*Entoles me telestes suntheths anatheshs, ypologismos DegC kai eksodos
apotelesmatwn sthn othonh tou ypologisth*/
DegC+=20.0;
DegF=DegC*9.0/5.0 + 32.0;
printf("%6.2lf\t%6.2lf\n", DegC, DegF);
DegC+=20.0;
DegF=DegC*9.0/5.0 + 32.0;
printf("%6.2lf\t%6.2lf\n", DegC, DegF);
DegC+=20.0;
DegF=DegC*9.0/5.0 + 32.0;
printf("%6.2lf\t%6.2lf\n", DegC, DegF);
DegC+=20.0;
DegF=DegC*9.0/5.0 + 32.0;
printf("%6.2lf\t%6.2lf\n", DegC, DegF);
DegC+=20.0;
DegF=DegC*9.0/5.0 + 32.0;
printf("%6.2lf\t%6.2lf\n", DegC,
DegF);
}
Epekshghsh oti h timh tou DegC kathe
fora allazei kata 20 me ton telesth suntheths anatheshs kai panta
kratietai h teleutaia timh tou. Epishs, epishmansh oti tha
mporousame na eixame xrhsimopoihsei mono ena printf statement ean
eixame orisei 6 diaforetikes metavlhtes gia tous vathmous Kelsiou kai
alles toses gia tous vathmous Kelvin, p.x DegC1,...,DegC6 kai
DegF1,...,DegF6.
Paradeigma 2
Eksoikeiwsh me dhlwseis statherwn, eisagwgh apo plhktrologio kai
xrhsh diaforwn telestwn gia prakseis
Programma metatrophs deuteroleptwn se lepta kai deuterolepta.
/*Erg6_2.c Programma metatrophs deuteroleptwn se lepta kai
deuterolepta*/
#include <stdio.h>
#define SEC_ANA_MIN 60 /*deuterolepta ana lepto*/
main()
{
int sec, min, ypoloipo;
printf("Metatroph deuteroleptwn se prwta lepta kai deuterolepta\n"
"Dwste ton
arithmo deuteroleptwn pou thelete na metatrepsete\n");
scanf("%d",
&sec);
/*Diavasma arithmou deuteroleptwn*/
min = sec/SEC_ANA_MIN; /*arithmos leptwn(akeraio meros ths diaireshs)*/
ypoloipo = sec%SEC_ANA_MIN; /*arithmos deuteroleptwn pou
perisseoun*/
printf("Ta %d deuterolepta einai %d prwta lepta kai %d deuterolepta\n",
sec, min,
ypoloipo);
}
Epekshghsh oti edw xthsimopoioume th
diairesh gia na krathsoume to akeraio meros pou isodynamei me ton
arithmo leptwn kai epishs xrhsimopoioume ton telesth % gia na paroume
to ypoloipo ths diaireshs pou dinei ton arithmo deuteroleptwn pou
perisseuoun