0% found this document useful (0 votes)
13 views2 pages

7 Array Manipulation in C

1. The document describes how to sort an array of integers in ascending order using a bubble sort algorithm. 2. It also explains how to multiply two matrices together to produce a resulting matrix. 3. Examples are provided of sorting an array and multiplying matrices with sample input and output.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views2 pages

7 Array Manipulation in C

1. The document describes how to sort an array of integers in ascending order using a bubble sort algorithm. 2. It also explains how to multiply two matrices together to produce a resulting matrix. 3. Examples are provided of sorting an array and multiplying matrices with sample input and output.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

ÌÓÈÑ-ÕØÓÈÑ ÌÊÓÒ

1 Õ³ñíýãò
Õî¼ð õýìæýýñò õ³ñíýãòèéã õýðýãëýã÷ýýñ óíøààä áóöààí õýâëýõ êîä.

1 # include < stdio .h >


2 # include < stdlib .h >
3
4 int main ()
5 {
6 int i , j , n , m , a [100][100];
7 printf ( " Mor baganii toog , oruul :\ n " ) ;
8 scanf ( " % d % d " , &n , & m ) ;
9 for ( i = 0; i < n ; i ++) { /* mor bolgonii huvid */
10 for ( j = 0; j < m ; j ++) /* tuxain mornii bagana buriin huvid */
11 scanf ( " % d " , & a [ i ][ j ]) ; /* i - r mornii , j - r bagand utga unshih */
12 }
13
14 for ( i = 0; i < n ; i ++) {
15 for ( j = 0; j < m ; j ++)
16 printf ( " % d " , a [ i ][ j ]) ;
17 printf ( " \ n " ) ; /* neg mor duussan tul shine mor hevleh */
18 }
19 return 0;
20 }

Àíãèä
1. Äàðààõ ïðîãðàìûã áè÷èæ àæèëëóóëààä, debugger àøèãëàí ïðîãðàìûí àëõàì á³ðä õóâü-

ñàã÷äûí óòãà õýðõýí °°ð÷ë°ãä°æ áàéãààã äýâòýðòýý äîîðõ õ³ñíýãòèéã çóðàí õàðóóë.

1 # include < stdio .h >


2
3 int main ()
4 {
5 int i , n , j , a [10] , k , tmp ;
6 scanf ( " % d " , & n ) ;
7 for ( i = 0; i < n ; i ++)
8 scanf ( " % d " , & a [ i ]) ;
9
10 for ( i = 0; i < n ; i ++) {
11 k = i;
12 for ( j = i + 1; j < n ; j ++) {
13 if ( a [ k ] > a [ j ]) {
14 k = j;
15 }
16 }
17 tmp = a [ k ];
18 a [ k ] = a [ i ];
19 a [ i ] = tmp ;
20 }
21
22 for ( i = 0; i < n ; i ++)
ÌÓÈÑ-ÕØÓÈÑ ÌÊÓÒ

23 printf ( " % d " , a [ i ]) ;


24 return 0;
25 }

i j k tmp n a[0] a[1] a[2] a[3] a[4]

2. Ñàãñàí á°ìá°ãèéí òýìöýýíä àíãèéíõàí äàíäàà °íä°ð õ³³õä³³äèéã îðîëöóóëàõààð øèé-

äýí, áîëîìæòîé õ³³õäèéí òîîã îëîõîîð áîëîâ. Àíãèä áàéãàà õ³³õä³³äèéí òîî áîëîõ

1 ≤ n < 100 òîîã àâ÷, äàðààãààð íü òýäíèé °ä°ð áîëîõ n øèðõýã òîîíóóäûã óíøààä

äóíäæààñ äýýø °íä°ðòýé õýäýí õ³³õýä áàéãààã îë.

3. 1 ≤ n < 100 òîî, äàðàà íü äàãàëäàõ n øèðõýã òîîíóóäûã õýðýãëýã÷ýýñ óíøèí õ³ñíýãòýä

õàäãàëæ, õ³ñíýãòýý òýãø õýìòýé ýñýõèéã øàëãà. Òýãø õýìòýé ãýæ õ³ñíýãòèéã óðäààñ íü

÷, õîéíîîñ íü ÷ õýâëýñýí àäèë òîîíóóä õýâëýãääýã áàéõûã õýëíý. Æèøýý íü: 5, 7, 8, 7, 5

ãýñýí òîîíóóä õ³ñíýãòýä õàäãàëàãäñàí áîë òýãø õýìòýé þì.

4. n×m õýìæýýòýé õ³ñíýãò °ã°ãä°õ°ä õàìãèéí îëîí òýãø òîî àãóóëñàí áàãàíûã îë.

Ãýðò
1. n×m õýìæýýñò õ³ñíýãòèéã äàðààõ áàéäëààð ä³³ðãý. Æèøýý íü n = 4, m = 2 áîë

1 1
2 2
3 3
4 4

2. n òîî °ã°ãä°õ°ä õ³ñíýãòèéã äîîðõ ìàÿãààð ä³³ðãý. n=4 áîë

1 2 3 4
2 3 4 3
3 4 3 2
4 3 2 1

3. An×m , Bm×k õî¼ð ìàòðèöûã õýðýãëýã÷ýýñ àâ÷ õîîðîíä íü ³ðæ³³ëýí Cn×k ìàòðèöûã õýâëýí

õàðóóë.

You might also like