Presentation is loading. Please wait.

Presentation is loading. Please wait.

Daprogramebis safuZvlebi leqcia #4 2009-2010 sasw.w. I semestri Tsu asoc. prof. naTela arCvaZe Tsu asoc. prof. naTela arCvaZe Tsu, zusti da sabunebismetyvelo.

Similar presentations


Presentation on theme: "Daprogramebis safuZvlebi leqcia #4 2009-2010 sasw.w. I semestri Tsu asoc. prof. naTela arCvaZe Tsu asoc. prof. naTela arCvaZe Tsu, zusti da sabunebismetyvelo."— Presentation transcript:

1 daprogramebis safuZvlebi leqcia #4 2009-2010 sasw.w. I semestri Tsu asoc. prof. naTela arCvaZe Tsu asoc. prof. naTela arCvaZe Tsu, zusti da sabunebismetyvelo mecnierebaTa fakulteti, kompiuterul mecnierebaTa mimarTuleba 1

2 wina leqciaze: marTvis Setyobinebebi pirobiTi: if Setyobineba if-else Setyobineba ciklis: while Setyobineba break Setyobineba continue Setyobineba 2

3 Tema: masivebi da ricxvebis wakiTxva tipi masivis_saxeli [ ganzomileba ] int data_list[3]; masivis elementebia: data_list[0], data_list[1], data_list[2] data_list[3] - ar aris elementi 3

4 magaliTi: davTvaloT 4 ricxvis jami da saSualo ariTmetikuli float data[4]; /* cvladebi, romelTaTvisac viTvliT jams da saSualo mniSvnelobas */ float total; /* cvladi jamisTvis */ float average; /* cvladi saSualo mniSvnelobisTvis */ int main() { data[0] = 54.0; data[1] = 18.0; data[2] = 34.0; data[3] = 91.0; total = data[0] + data[1] + data[2] + data[3]; average = total / 4.0; printf("Total =%f\t Average =%f\n", total, average); return (0);} 4

5 striqonebi char saxeli [ ganzomileba ] \0 - end-of-string char name[6]; int main() { name[0] = H; name[1] = e; name[2] = l; name[3] = l; name[4] = o; name[5] = \0; return (0); } 5

6 striqonuli mudmivebi - "..." name = Hello; /* = arasworia */ magaliTi: include char name[6]; int main() { strcpy(name, "Hello"); /* name - is inicializeba */ printf("%s\n", name); /* name - is dabeWdva */ return (0); } 6

7 funqcia ganmarteba strcpy( striqoni1, striqoni2 ) striqoni2-is asli gadaaqvs striqoni1 -Si strcat( striqoni1, striqoni2 ) striqoni1-is bolos miabams striqoni2-s length = strlen( striqoni ) miiReba striqonis sigrZe\0 gareSe strcmp( striqoni1, striqoni2 )0, Tu striqonebi tolia. winaaRmdeg SemTxvevaSi aranulovani sididea striqonuli mudmiva - ormag brWyalebSi (), mag.X - ikavebs or baits simboluri mudmiva - erTmag brWyalebSi (). mag.X - ikavebs erT baits. standartuli funqciebi 7

8 magaliTi #include char first[100]; /* saxeli */ char last[100]; /* gvari */ char full_name[200]; /* saxeli da gvari erTad */ int main(){ strcpy(first, "Galaqtion"); /* saxelis inicializeba */ strcpy(last, "Tabidze");/* gvaris inicializeba */ strcpy(full_name, first); /* full = "Galaktion" */ strcat(full_name, " "); /* full = " Galaktion " */ strcat(full_name, last); /* full = " Galaktion Tabidze" */ printf("The full name is %s\n", full_name); system("PAUSE"); return (0); } 8

9 striqonebis wakiTxva da beWdva gets ( parametri ); Enter - \n(end-of-line) amatebs \0 puts ( parametri ); #include 9

10 magaliTi striqonebze: #include char line[100]; int main() { printf("Enter a line: "); gets(line); puts("We have read:"); puts(line); printf("The length of the line is: %d\n", strlen(line)); return (0); } 10

11 mravalganzomilebiani masivebi tipi masivis_saxeli [ ganz1 ] [ ganz2 ] int matrix[3][4]; 3x4=12 elementi float four_dimensions[10][12][9][5]; 10x12x9x5 elementi 11

12 masivis inicializeba int x[3] = {11, 823, 43}; igivea, rac x[0]= 11; x[1]=823; x[2]=43; int x[] = {11, 823, 43}; int matrix[2][3] ={{1, 2, 3},{10, 20, 30}}; int matrix[2][3] = {1, 2, 3, 10, 20, 30}; char name[] = {'H', 'e', 'l', 'l', 'o','\0'}; char name[] = Hello; char name[50] = Hello; elem. raodenobaa 6=5+1 ( '\0') 12

13 scanf( formati, & cvl1, & cvl2...); #include int value; int main() { printf("Enter a value: "); scanf("%d", &value); printf("Twice %d is %d\n", value, value * 2); system("PAUSE"); return (0); } ricxvebis wakiTxva 13

14 informaciis Setana-gamotanis gadamisamarTeba. funqcia freopen stdin- Setanis standartuli nakadi stdout- gamotanis standartuli nakadi stderr- Secdomebis standartuli nakadi failidan wakiTxva – reJimia r(read) freopen ( striqoni1, striqoni2, stdin); freopen ("c:\monacemebi\data.txt", "r", stdin); 14

15 failSi Cawera-reJimi w (write) freopen ( striqoni1, striqoni2, stdout); freopen ("c:\shedegi.txt", "w", stdout); magaliTi : #include int main() { int a, b, c; float sashualo; freopen( "monacemebi.txt", "r", stdin); scanf("%d%d%d", &a, &b, &c); sashualo =(a+b+c)/3.; freopen( "pasuxi.txt", "w", stdout); printf("%d %d %d ricxvebis ", a, b, c); printf("sashualo ariTmetikuli = %f ", sashualo); return 0; } 15

16 kursis kategoriebi: kompiuteruli mecnierebebi kursi: daprogramebis safuZvlebi- 2009 Semodgoma : http://moodle.science.tsu.ge/ 16


Download ppt "Daprogramebis safuZvlebi leqcia #4 2009-2010 sasw.w. I semestri Tsu asoc. prof. naTela arCvaZe Tsu asoc. prof. naTela arCvaZe Tsu, zusti da sabunebismetyvelo."

Similar presentations


Ads by Google