ERGASTHRIO
5
Eisagwgika programmata sth glwssa C
1o Programma
Anoigma arxeiou me to vi kai suggrafh programmatos me titlo Erg5_1.c
/****************************************************************
To prwto mou programma se C
NA SYNHTHIZW APO TWRA NA GRAFW
SXOLIA
******************************************************************/
#include <stdio.h>
main()
{
int mera, mhnas, etos, etos_sp;
/*Dhlwseis metavlhtwn*/
/* Orizw tis times twn metavlhtwn*/
mera=12;
mhnas=11;
etos=2004;
etos_sp=1;
/*Protaseis eksodou se othonh */
printf("To prwto mou programma sth glwssa programmatismou C! \n");
printf("H hmeromhnia shmera einai \t\
%d/%d/%d. \n", mera, mhnas, etos);
printf("Vriskomai sto %do etos twn spoudwn mou. \n", etos_sp);
/*********************************************************************
H ENTOLH POY AKOLOYTHEI DIXNEI PWS KANOYME OUTPUT MESW printf
MIAS APLHS PRAKSHS
**********************************************************************/
printf("To fthinopwro tou %d tha vriskomai sto %do etos \
twn spoudwn mou. \n", etos+1, etos_sp+1);
printf("Einai swsto auto to programma!\n\n");
/*******************Edw teleiwnei to programma
mou***********************/
}
COMPILE ME
gcc Erg5_1.c
ALLA KAI ME
gcc -o Erg5_1 Erg5_1.c
ERWTHSEIS:
a) PWS THA BALW TO GRAMMA <C> STO PRWTO printf MESA SE " "
\"C\"
b) PWS THA ANTIKATASTHSW STO TELEYTAIO printf TO THAYMASTIKO ME
TO AGGLIKO ERWTHMATIKO
\?
2o Programma
Morfopoihsh eksodou akeraiwn,
pragmatikwn kai pragmatikwn grammenwn se episthmonikh grafh. Anoigma me
vi arxeiou Erg5_2.c kai suggrafh tou parakatw kwdika:
/****************************************************************
Programma morfopoihshs eksodou arithmwn
*****************************************************************/
#include <stdio.h>
main()
{
/*Dhlwseis metavlhtwn*/
int i1;
float x1, pi;
/*Orismos metavlhtwn*/
i1 = 50;
pi = 3.14159;
x1= 1234567890.12;
/*Morfopoihsh Akeraiou*/
printf("i1 =\n \
\r[%d] \t(xwris euros pediou) \n \
\r[%1d] \t(euros pediou mikrotero apo to pragmatiko) \n \
\r[%10d] \t(euros pediou megalutero apo to pragmatiko)\n\n",i1, i1, i1);
/*Morfopoihsh Pragmatikou*/
printf("pi = \n \
\r[%f]
\t(xwris prodiagrafes) \n \
\r[%15.5f]
\t(euros pediou megalutero apo to pragmatiko) \n \
\r[%7.2f]
\t(akriveia mikroterh apo thn pragmatikh) \n \
\r[%9.f]
\t(den orizetai h akriveia) \n \
\r[%.9f]
\t(den orizetai to euros pediou) \n\n", pi, pi, pi, pi, pi);
/*Morfopoihsh Pragmatikou se episthmonikh grafh*/
printf("x1 = \n \
\r[%e]
\t(xwris prodiagrafes) \n \
\r[%8.5e]
\t(euros pediou kai akriveia einai mesaiou megehtous) \n \
\r[%4.1e]
\t(euros pediou kai akriveia einai mikrou
megehtous) \n \
\r[%18.2e]
\t(megalo euros pediou, mikrh akriveia) \n", x1, x1, x1, x1);
/*Telos programmatos*/
}