1 / 16

daprogramebis safuZvlebi leqcia #4

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.

erikaw
Download Presentation

daprogramebis safuZvlebi leqcia #4

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. wina leqciaze: marTvisSetyobinebebi pirobiTi: • if Setyobineba • if-elseSetyobineba ciklis: • while Setyobineba break Setyobineba continue Setyobineba

  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

  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);}

  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); }

  6. 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); }

  7. striqonuli mudmiva - ormag brWyalebSi (″), mag. ″X″ - ikavebs or baitssimboluri mudmiva - erTmag brWyalebSi (′). mag. ′X′ - ikavebs erT baits.standartuli funqciebi

  8. 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); }

  9. striqonebis wakiTxva da beWdva gets (parametri); Enter - ′\n′(end-of-line) amatebs ′\0′ puts (parametri); #include <stdio.h>

  10. 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); }

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

  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')

  13. 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); }

  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);

  15. 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; }

  16. kursis kategoriebi: kompiuteruli mecnierebebi kursi: daprogramebis safuZvlebi- 2009 Semodgoma მასწავლებელი: ნათელა არჩვაძე • http://moodle.science.tsu.ge/

More Related