180 likes | 355 Views
daprogramebis safuZvlebi leqcia #5. 2009-2010 sasw.w. I semestri Tsu asoc. prof. naTela arCvaZe Tsu, zusti da sabunebismetyvelo mecnierebaTa fakulteti, kompiuterul mecnierebaTa mimarTuleba. wina leqciaze:.
E N D
daprogramebissafuZvlebileqcia #5 2009-2010 sasw.w. I semestri Tsu asoc. prof. naTela arCvaZe Tsu, zusti da sabunebismetyvelo mecnierebaTa fakulteti, kompiuterul mecnierebaTa mimarTuleba
wina leqciaze: ricxvebis wakiTxvascanf(formati, &cvl1, &cvl2 . . .); informaciis Setana-gamotanis gadamisamarTeba. funqcia freopen freopen (misam., reJimi, nakadis_sax); freopen ("c:\monacemebi\data.txt", "r", stdin); freopen ("c:\shedegi.txt", "w", stdout);
Tema: ricxvebis tipebi mTeli ricxvebis tipebi long int cvladis-saxeli ; short int cvladis-saxeli ; sizeof(short)≤ sizeof( int)≤ sizeof(long) signedlongint result; igivea, rac long result;
#include<stdio.h> #include<stdlib.h> #include <limits.h> int main(){ int x = INT_MIN, y = INT_MAX; unsigned int ux = UINT_MAX; long int lx = LONG_MIN, ly = LONG_MAX; unsigned long int lu = ULONG_MAX; short int sx = SHRT_MIN, sy = SHRT_MAX; unsigned short int su = USHRT_MAX; printf("int ikavebs %d baits\n", sizeof(int)); printf("misi diapazonia %d : %d\n", x,y); printf("unsigned int-is diapazonia 0 : %u\n", ux); printf("long int ikavebs %d baits\n", sizeof(long)); printf("misi diapazonia %ld : %ld\n", lx,ly); printf("unsigned long-is diapazonia 0 : %lu\n", lu); printf("short int ikavebs %d baits\n", sizeof(short)); printf("misi diapazonia %hd : %hd\n", sx,sy); printf("unsigned short int-is diapazonia 0 : %hu\n", su); return 0;}
programis Sedegia: int ikavebs 4 baits misi diapazonia -2147483648 : 2147483647 unsigned int-is diapazonia 0 : 4294967295 long int ikavebs 4 baits misi diapazonia -2147483648 : 2147483647 unsigned long-is diapazonia 0 : 4294967295 short int ikavebs 2 baits misi diapazonia -32768 : 32767 unsigned short int-is diapazonia 0 : 65535
tipi char diapazoni (-128)-dan 127-mde. unsignedchar diapazoni 0–dan 255–mde. ASCII (American Standard Code for Information Interchange) scanf("%c", &symbol); -araa rekomendirebuli <stdio.h> - getchar(); putchar(); char ch; ch = getchar(); -simbolos wakiTxva putchar(simbolo); -ekranze dabeWdva mag. char ch ='Z'; putchar(ch); • <conio.h>-is funqcia getch() msgavsia • system("PAUSE") -is
magaliTi: #include<stdio.h> #include<conio.h> int main() { char p; printf("Enter a symbol : "); p=getchar(); /* simbolos wakiTxva */ printf("Symbol is : "); putchar(p); /* simbolos beWdva */ getch(); /* ekranis gaCereba */ return 0; }
namdvili ricxvebis tipebi float, double, long double float f; /* namdvili ricxvi */ double d; /* ormagi sizustis */ long double x; /* gazrdili sizustis */ int main() { printf("float ikavebs %d baits\n", sizeof(f) ); printf("double ikavebs %d baits\n", sizeof(d) ); printf("long double - %d baits\n", sizeof(x) ); return 0; } programis Sesrulebis Sedegi: float ikavebs 4 baits double ikavebs 8 baits long double - 12 baits
specifikatorebi printf() da scanf() funqciebSi ganacxadebi mudmivebze consttipicvladis_saxeli= mniSvneloba ; magaliTad, constfloat PI = 3.141592;
TeqvsmetobiTi da rvaobiTi mudmivebi • ricxvi iwyeba ″0x″–iT - TeqvsmetobiTi • ricxvi iwyeba ″0″–iT - rvaobiTi ricxvi int k = 020+0x20+20; //8-biTi, 16-biTi da 10-biTi ocebis jami printf("%d\n",k); //daibeWdeba 68 (16+32+20)
magaliTi:#include <stdio.h>#include <stdlib.h>int main() {int x = 100;printf("dec=%d;octal=%o;hex=%x\n",x,x,x);printf("dec=%d;octal=%#o;hex=%#x\n",x,x,x); system("PAUSE");return 0;}programis Serulebis Sedegi: dec = 100; octal = 144; hex = 64 dec = 100; octal = 0144; hex = 0x64
for ciklisoperatori for (inicializeba; piroba; koreqcia) Setyobineba; while (pirobis Semowmeba ) { Setyobineba; koreqcia; }
magaliTi: SevkriboT 5 ricxvi (while cikliT) #include <stdio.h> #include <stdlib.h> int total; /* yvela ricxvis jami */ int current; /* damxmare cvladi */ int counter; /* ganmeorebaTa mTvleli */ int main(){ total=0; counter=0; while(counter<5){ printf("number? "); scanf("%d", ¤t); total+=current; ++counter; } printf("The grand total is %d\n", total); return (0); }
magaliTi: SevkriboT 5 ricxvi (for cikliT) #include <stdio.h> #include <stdlib.h> int total; /* yvela ricxvis jami */ int current; /* damxmare cvladi */ int counter; /* ganmeorebaTa mTvleli */ int main(){ total=0; for (counter=0;counter<5;++counter){ printf("number? "); scanf("%d", ¤t); total+=current; } printf("The grand total is %d\n", total); return (0); }
konsultacia: yovel paraskevs 16 saaTze 805 auditoriaSi kursis kategoriebi: kompiuteruli mecnierebebi kursi: daprogramebis safuZvlebi- 2009 Semodgoma მასწავლებელი: ნათელა არჩვაძე http://moodle.science.tsu.ge/