ERGASTHRIO 7
Domes Elegxou if kai Brogxoi for / while

Programma 1 - Domh elegxou if-else kai if-else if / sundiasmos me brogxo while
Programma ektimhshs epidoshs 10 foithtwn analoga me th vathmologia tous


/*Erg7_1.c   EKTIMHSH EPIDOSHS FOITHTWN */
#include <stdio.h>

main()
{
int i;
double vathmos;

printf("EKTIMHSH EPIDOSHS 10 FOITHTWN\n");
printf("Frontiste oi vathmoi na einai metaksy 0 kai 10!\n");
printf("Oi vathmoi mporei kai na mhn einai akeraioi!\n");

i=1;

while(i<=10)
{
printf("Dwse ton vathmo tou %dou foithth\n",i);
scanf("%lf", &vathmos);
if (vathmos > 10. || vathmos < 0.0)
{
printf("Auto DEN ksanagine!!"
" Den vazw vathmo ston %do foithth\n", i);
}
else
{
if (vathmos >= 8.)
{
printf("O %dos foithths ta phge polu kala! "
"Phre %4.2lf!\n", i, vathmos);
}
else if (vathmos >=6.)
{
printf("O %dos foithths den ta phge asxhma! "
"Phre %4.2lf!\n", i, vathmos);
}
else if (vathmos >=5.)
{
printf("Ouf! O %dos foithths isa pou perase to "
"mathhma me %4.2lf!\n", i, vathmos);
}
else if (vathmos >= 4.)
{
printf("Atuxia! O %dos foithths kophke sto "
"mathhma me %4.2lf!\n", i, vathmos);
}
else if (vathmos>=3.)
{
printf("O %dos foithths tha mporouse na "
"eixe perasei an diavaze ligo pio polu. "
"Kophke mono me %4.2lf!\n", i, vathmos);
}
else
{
printf("Panwlethria! Den theleis na ksereis "
"me ti vathmo kophke o %dos foithths!",i);
}
}
i++;
}
}


Programma 2 - Vrogxos for
Programma metatrophs vathmwn Kelsiou (-30, 100) me vhma 10 se Farenait kai apothhkeush eksodou se arxeio me onoma CseF.out
PROSOXH: TWRA H METAVLHTH DegC EXEI DHLWTHEI WS AKERAIA



/*Erg7_2.c  Programma metatrophs vathmwn Kelsiou se Farenait*/
#include <stdio.h>

main()

{

int DegC;
double DegF;
FILE *out_arxeio;

/*Anoigma arxeiou gia grapsimo*/
out_arxeio=fopen("CseF.out", "w");

fprintf(out_arxeio, "Pinakas Vathmwn Kelsiou se Farenait\n\n"
"Vathmoi\t\tVathmoi\n"
"Kelsiou\t\tFarenait\n");

/*Brogxos for gia metatroph metaksy -30 kai 100 Kelsiou*/
for (DegC=-30; DegC<=100; DegC+=10)
{
DegF=DegC*9.0/5.0 + 32.0;
fprintf(out_arxeio,"%5d\t\t%6.2lf\n", DegC, DegF);
}

/*Kleisimo arxeiou*/
fclose(out_arxeio);
}