Слайд 1daprogramebis safuZvlebi
leqcia #4
2009-2010 sasw.w. I semestri
Tsu asoc. prof. naTela arCvaZe
Tsu, zusti da sabunebismetyvelo mecnierebaTa fakulteti, kompiuterul mecnierebaTa mimarTuleba
Слайд 2wina leqciaze:
marTvis Setyobinebebi
pirobiTi:
if Setyobineba
if-else Setyobineba
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
Слайд 4magaliTi: 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);}
Слайд 5striqonebi
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); }
Слайд 6striqonuli 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); }
Слайд 7striqonuli mudmiva - ormag brWyalebSi (″),
mag. ″X″ - ikavebs or
baits
simboluri mudmiva - erTmag brWyalebSi (′).
mag. ′X′ - ikavebs erT baits.
standartuli funqciebi
Слайд 8magaliTi
#include
#include
#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); }
Слайд 9striqonebis wakiTxva da beWdva
gets (parametri);
Enter - ′\n′(end-of-line) amatebs ′\0′
puts
(parametri);
#include
Слайд 10magaliTi striqonebze:
#include
#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);
}
Слайд 11
mravalganzomilebiani masivebi
tipi masivis_saxeli [ ganz1 ] [ ganz2 ]
int
matrix[3][4]; 3x4=12 elementi
float four_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')
Слайд 13scanf(formati, &cvl1, &cvl2 . . .);
#include
#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
Слайд 14informaciis 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);
Слайд 15failSi 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; }
Слайд 16
kursis kategoriebi:
kompiuteruli mecnierebebi
kursi: daprogramebis safuZvlebi-
2009 Semodgoma
მასწავლებელი: ნათელა არჩვაძე
http://moodle.science.tsu.ge/