160 likes | 170 Views
This course covers the basics of arrays and data input/output in the C programming language. Topics include array declaration and initialization, array manipulation, and reading/writing data to files.
E N D
daprogramebissafuZvlebileqcia #4 2009-2010 sasw.w. I semestri Tsu asoc. prof. naTela arCvaZe Tsu, zusti da sabunebismetyvelo mecnierebaTa fakulteti, kompiuterul mecnierebaTa mimarTuleba
wina leqciaze: marTvisSetyobinebebi pirobiTi: • if Setyobineba • if-elseSetyobineba ciklis: • while Setyobineba break Setyobineba continue Setyobineba
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
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);}
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); }
striqonuli mudmivebi - "..." name = ″Hello″; /* = arasworia */ magaliTi: include <string.h> char name[6]; int main() { strcpy(name, "Hello"); /* name -is inicializeba */ printf("%s\n", name); /* name -is dabeWdva */ return (0); }
striqonuli mudmiva - ormag brWyalebSi (″), mag. ″X″ - ikavebs or baitssimboluri mudmiva - erTmag brWyalebSi (′). mag. ′X′ - ikavebs erT baits.standartuli funqciebi
magaliTi #include <string.h> #include <stdio.h> #include <stdlib.h> 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); }
striqonebis wakiTxva da beWdva gets (parametri); Enter - ′\n′(end-of-line) amatebs ′\0′ puts (parametri); #include <stdio.h>
magaliTistriqonebze: #include <string.h> #include <stdio.h> 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); }
mravalganzomilebiani masivebi tipi masivis_saxeli [ ganz1 ] [ ganz2 ] • int matrix[3][4]; 3x4=12 elementi • floatfour_dimensions[10][12][9][5]; 10x12x9x5 elementi
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')
ricxvebis wakiTxva scanf(formati, &cvl1, &cvl2 . . .); #include <stdio.h> #include <stdlib.h> int value; int main() { printf("Enter a value: "); scanf("%d", &value); printf("Twice %d is %d\n", value, value * 2); system("PAUSE"); return (0); }
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);
failSi Cawera-reJimi w (write) freopen (striqoni1, striqoni2, stdout); freopen ("c:\shedegi.txt", "w", stdout); magaliTi: #include<stdio.h> 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; }
kursis kategoriebi: kompiuteruli mecnierebebi kursi: daprogramebis safuZvlebi- 2009 Semodgoma მასწავლებელი: ნათელა არჩვაძე • http://moodle.science.tsu.ge/