150 likes | 339 Views
daprogramebis safuZvlebi leqcia #2. 2009-2010 sasw.w. I semestri Tsu asoc. prof. naTela arCvaZe Tsu, zusti da sabunebismetyvelo mecnierebaTa fakulteti, kompiuterul mecnierebaTa mimarTuleba. 1. wina leqciaze.
E N D
daprogramebis safuZvlebileqcia #2 2009-2010 sasw.w. I semestri Tsu asoc. prof. naTela arCvaZe Tsu, zusti da sabunebismetyvelo mecnierebaTa fakulteti, kompiuterul mecnierebaTa mimarTuleba
1. wina leqciaze • Sesavali daprogramebis ena C-Si • stili programis daweris wesebi: • programa dayaviT calkeul procedurebad da SeamcireT sirTulis xarisxi • grZel instruqciebs Tavi aarideT-programa ase ufro advili aRsaqmeli iqneba • ecadeT Tqveni programa iyos rac SeiZleba martivi da naTeli
programis ZiriTadi struqtura /************************************* * . . . sawyisikomentarebi . . . * *************************************/ . . . ganacxadebi monacemebze . . . int main () { ... Sesrulebadi Setyobinebebi... return (0); }
magaliTi hello.cpp. /********************************************* * hello -- program to print out "Hello World" * * Not an especially earth-shattering program. * * * Author: Steve Oualline. * * * * Purpose: Demonstration of a simple program. * * * Usage: * Runs the program and the message appears. * **********************************************/ #include <stdio.h> #include <stdlib.h> int main() { /* Tell the world hello */ printf("Hello World\n"); system (“PAUSE”); return (0); }
gamosaxulebebi • martivi operatorebi: +, _, *, /, % (naSTi mT. gayofisas miR.) /* Sedegi ar aqvs */ int main() { ( 1 + 2 ) * 3; return (0); }
cvladebis saxelebi • gamoiyeneba asoebi, cifrebi da qveda tires simbolo ( _) • saxeli ar SeiZleba cifriT iwyebodes • sworea: sashualo, Pi, studentebis_raodenoba, gio, Gio,GIO • arasworea: 2_cda, fasi$, studentebis raodenoba, int, for
ganacxadi cvladebzemTeli ricxvebi tipi saxeli; /* komentari */ intsaxeli;/* komentari */ • 32 biti (4 baiti) - 2147483648(-231)-dan 2147483647(231-1)-mde • 16 bits (2 baits), -32768(-215)-dan 32767(215-1)-mde. • limits.h - mudmivebi, romelTa mniSvnelobebiaA sxvadasxva diapazonis sazRvrebi (mag.,INT_MAX, INT_MIN)
funqciaprintf printf ( formati, gamos1, gamos2, . . . ); #include <stdio.h> #include <stdlib.h> int term;/* termgamoiyeneba or gam. */ int main() { term = 3 * 5; printf ("gaormagebuli %d aris %d \n", term, 2 * term); printf ("gasammagebuli %d aris %d \n", term, 3 * term); system ("PAUSE"); return (0);}
namdvili ricxvebi floatcvladi;/*komentari*/ • 1 + 2 = 3 • 1.0 + 2.0 = 3.0 • 19 / 10 = 1 • 19.0 / 10.0= 1.9
magaliTi int i; /* mTeli tipis cvladi saxeliT i */ float x;/* mcocavwertiliani cvladi saxeliTx */ main() { x = 1.0/2.0; /* mianiWebs cvladx-smniS. 0.5 */ i= 1/3;/* mianiWebs cvlad i-s mniS. 0 */ x = (1/2)+(1/2); /* mianiWebs cvlads x -s mniSv. 0 */ x = 3.0/2.0; /* mianiWebs cvlad x-smniS. 1.5 */ i = x; /* mianiWebs cvlad i-smniS. 1 */ return (0); }
simboloebi char cvladi; /* komentari */ mmarTveli simboloebi: \b \f \n \r \t \‘ \“ \a
magaliTi #include <stdio.h> #include <stdlib.h> char char1; /* pirveli simbolo */ char char2; /* meore simbolo */ char char3; /* mesame simbolo */ int main() { char1='A'; char2='B'; char3='C'; printf("%c%c%c gardaiqmneba %c%c%c-ad\n", char1,char2,char3,char3,char2,char1); system (“PAUSE”); return(0); } pasuxi: ABC gardaiqmneba CBA-ad.