Scanf ôóíêö
• Ïðîãðàìì çîõèîõ våä õýðýãëýã÷ýýñ òºðºë ávðèéí ºãºãäºë
óíøèõ çàéëøãvé øààðäëàãà ãàðäàã. Ñè õýëýíä vvíèéã scanf
ávõíýýñ øèéäíý.
• ªãºãäºë óíøèõäàà èõýíõ våä printf , scanf õî¸ð ôóíêöûã õîñëóóëàí àæèëóóëäàã. Ýõëýýä printf–ýýð õýðýãëýã÷ýýñ óíøèõ óòãûí òóõàé áóþó àñóóëòàà õýâëýýä äàðàà íü scanf–ýýð óòãàà óíøäàã.
Áè÷èãäýõ õýëáýð
Scanf (Óäèðäëàãûí òýìäýãòvvä ìºð , [ õóâüñàã÷ ];
Áóþó
int scanf (“Óäèðäëàãûí òýìäýãò ìºð”, õóâüñàã÷ 1,... õóâüñàã÷ n );
Æèøýý íü : scanf (“%d”, & age);
Scanf (“%s”, name);
Scanf-‘í ävðýì
Scanf –ûí óäèðäëàãûí òýìäýãò ìºðèéã ÿìàð áàéäëààð áè÷ñýí ÿã ò¿¿íòýé àäèëààð õýðýãëýã÷ ãàðààñ ºãºãäºë îðóóëàõ ¸ñòîé.Õýðýãëýã÷ýýñ int , float , double , long ãýõ ìýò ýíãèéí òºðëèéí óòãûã óíøèõäàà & òýìäýãòèéã õóâüñàã÷ûí íýðèéí ºìíº çààâàë àøèãëàíà.Õàðèí õýðýãëýã÷ýýñ òýìäýãò ìºð áóþó òýìäýãò ìàññèâ óíøèõûã õ¿ñâýë & òýìäýãòèéã àøèãëàõã¿é.Òýìäýãò ìºð íü ººðºº õàÿã þì.( óäèðäëàãûí
Æèøýý 1
Int i, j , k;
Scanf (“%d %d %d”, &i ,&j, &k);
ýíý våä ãàðààñ îðóóëàõàä 5.10.15
Int year, month, day;
scanf (“%d %d %d”,&month,&day,&year);
ãàðààñ îðóóëàõäàà 0|07|02
Æèøýý 2
int I; char c; float f; long I;
char name [20];
scanf(“%d”,&i);
scanf(“%c”,&c);
scanf(“%f”,&f);
scanf(“%ld”,&l);
scanf(“%s”,name);
Æèøýý 3
scanf–ã àøèãëàõûí ºìíº çààâàë àñóóëò õýâëýíý.
Char name[20];
Printf (“òà íýðýý îðóóëíà óó? \n”); /*àñóóõ*/
Scanf (“%s”,name);
Getchar ôóíêöûí ôîðìàò
Ýíý íü ãàðààñ íýã øèðõýã òýìäýãò óíøèíà.
Õóâüñàã÷ getchar ( ); Ýíý íü inter òîâ÷ àâäàã.
Æèøýý 4
Printf (“ Íýã òýìäýãò îðóóëíà óó ? ”);
Ch=getchar ( );
Putchar ôóíêöûí ôîðìàò
Putchar-ààð àâñàí òýìäýãòèéã õýâëýäýã.
Putchar (Õóâüñàã÷ );
Æèøýý 5
Printf (“òà ýíý òýìäýãòèéã îðóóëæýý”);
Purchar ( ch );
Getch ôóíêö
Ýíý íü ãàðààñ çºâõºí íýã òýìäýãò óíøèíà. Òýãýõäýý getch íü îðóóëàõ ºãºãäëèéã áóôåðëýäýãã¿é.ªºðººð õýëáýë getchar øèã ºãºãä뺺 öóãëóóëàí enter òîâ÷ûã õvëýýäýããvé. Èéìýýñ áóðóó îðóóëñàí ºãºãä뺺 backspace òîâ÷îîð çàëðóóëíà.
Getch–‘í ôîðìàò
Õóâüñàã÷=getch ( ) ;
Æèøýý 6
Printf (“òà íýã òýìäýãò îðóóëàíà óó?”);
Ch= getch ( );
Putch-“í ôîðìàò
Putch (õóâüñàã÷);
Æèøýý 7
Printf (“òà ýíý òýìäýãòèéã îðóóëæýý:”);
Putch (ch);
Getche ôóíêö
Ãàðààñ íýã òýìäýã óíøèõ ôóíêö þì. Getch íü îðîëòûí òýìäýãòèéã äýëãýöýíä ä¿ðñýëäýããvé. Óã òýìäýãò íü ãàðààñ íýã òýìäýãò óíøèí , ò¿¿íèéã ìºí äýëãýöýíä ä¿ðñýëäýã ôóíêö þì. Ýíý íü getch , putch-‘í vvðãèéã äàâõàð ãvéöýòãýíý.
Ñè ïðîãðàììûí ávòýö
Ñè ïðîãðàììûí ávòöèéã àãóóëãààð íü äàðààõ 5 íü õýñýãò õóâààíà.
I. Õîëáîëòûí õýñýã
II. Òîãòìîëûã çàðëàõ õýñýã
III. Õóâüñàã÷ûã çàðëàõ õýñýã
IV. Ôóíêöûã çàðëàõ õýñýã
V. Víäñýí ôóíêö õýñýã
Õîëáîëòûí õýñýã
Ïðîãðàìä ñòàíäàðò ôóíêö õîëáîõ øààðäëàãà òóëãàðäàã áà õîëáîëòûã # include òvëõvvð vãèéí òóñëàìæòàé ãvéöýòãýíý.
Áè÷èãäýõ õýëáýð íü:
# include < ôàéëûí íýð>
# include “ ôàéëûí íýð ” 2 ÿíçààð áè÷èæ áîëíî.
Ôàéëûí íýð íü òóõàéí ôóíêöûã àãóóëàõ .h ºðãºëòýé ôàéëûí íýð áàéíà.
Ýäãýýð ôàéëóóä c:\ tc \ include ñàíä áàéðëàíà.
Ôàéëóóäûí æèøýý
Stdio.h- víäñýí îðîëò ãàðàëòûí ôóíêö¿¿ä ýíý ôàéëä òîäîðõîéëîãäîíî.
• Printf äýëãýöýíä ºãºãäºë õýâëýíý.
• Scanf ãàðààñ óòãà óíøèõ
Stdlib.h- òºðºë ávðèéí õºðâvvëýëòèéí ôóíêö ïðoãðàììûí óäèðäëàãà øèëævvëýõ ôóíêöóóä áàéíà.
Atoi–òýìäýãò ìºðèéã òîî áîëãîõ.
Itoa–òîîã òýìäýãò ìºð áîëãîõ .
Òîãòìîëóóäûã çàðëàõ õýñýã
Ýíý õýñýãò òîãòìîë õýìæèãäýõvvíèé íýð, àâàõ óòãûã çàðëàíà.
Const float pi=3.14
# define max 100
Õóâüñàã÷ûã çàðëàõ õýñýã
Ïðîãðàììä õýðýãëýãäýõ ãëîáàëü õóâüñàã÷äûã ýíä çàðëàíà.
Áè÷èãäýõ õýëáýð íü :
<õóâüñàã÷ûí òºðºë > < õóâüñàã÷ûííýð >;
Æèøýý
Int i, j ;
Char c;
Ãëîáàëü õóâüñàã÷
Ãëîáàëü õóâüñàã÷ ãýäýã íü ïðîãðàììûí àëü ÷ õýñýãò õàðàãäàõ óòãûã íü ººð÷èëæ áîëîõ õóâüñàã÷ þì.Ãëîáàëü õóâüñàã÷èéã äàðààõ 2 øèíæ ÷àíàðààð ÿëãàíà.
1) Ïðîãðàìûí àëü ÷ ôóíêö, ïðîöåäóð äîòðîîñ ò¿¿íèé óòãûã ººð÷èëæ áîëäîã.
2) Òvvíèé àìüäðàõ õóãàöàà íü ïðîãðàììûã äóóñàí äóóñòàë vðãýëæèëíý.
Ôóíêöûã çàðëàõ õýñýã
Ýíä õýðýãëýã÷èéí òîäîðõîéëñîí ôóíêö ïðîöåäóðóóäûã(äýä ïðîãðàì ) áàéðëóóëíà. Ýíý äýä ïðîãðàìì ººðèéí ãýñýí íýðòýé áà víäñýí ïðîãðàììûí õààíààñ íü ÷ íýðýýð äóóäàæ õýðýãëýæ áîëíî.
Ôóíêöûí íýð ( ïàðàìåòóóä )
{< õóâüñàã÷äûã çàðëàõ õýñýã > ëîêàëü õóâüñàã÷
< õóâüñàã÷ûí ôóíêöûí áèå >
}
Ëîêàëü õóâñàã÷
Ǻâõºí òóõàéí ôóíêö äîòðîî õýðýãëýãäýíý. Àìüäðàõ õóãàöàà íü ôóíêöûí àæèëàõ õóãàöàà þì.
No comments:
Post a Comment