You are on page 1of 34

,

-10

: . //


.
.
www.emust.edu.mn

.
.
#include <iostream>
using namespace std;
int main()
{
int age[4];
for (int i = 0; i < 4; ++i)
{ cout << "Nasaa oruulj ogno uu:"; cin >> age[i]; }
for (int i = 0; i < 4; ++i)
{ cout <<endl<< "Tanii oruulsan ni:"<<age[i]; }
return 0;
}

, .
, .

: 44
: 16
: 23
: 68

: 44
: 16
: 23
: 68


.
.
.

. 4
.
.


.
. ,
.
(4 * 2 ) 8
. 0 .
(n-1) (n !).
0-3 4 .

2 .
.

cin >> age[i];

cout << endl<< << age[i];

j
. j
.


. 6
, .
#include <iostream>
using namespace std;
const int SIZE=6;
int main()
{ float sales[SIZE];
cout<<endl<<"6 odriin orlogiig daraaluulan oruulna uu"<<endl;
for (int i = 0; i < SIZE; ++i)
cin>>sales[i];
float total=0;
for (int i = 0; i < SIZE; ++i)
total+=sales[i];
float average=total/SIZE;
cout<<"Dundaj orlogo: "<<average; }

.

6
352.64
867.70
781.32
867.35
746.21
189.45
=634.11


, .

const int SIZE=6;


.

.
.
.



. .
#include <iostream>
using namespace std;
int main()
{
int sar, odor, niit_odor, sariin_odruud[12]={31,28,31,30,31,30,31,31,30,31,30,31};
cout<<endl<<"Sariing oruulna uu (1 to 12):";
cin >>sar;
cout <<"Odriig oruulna uu (1 to 31):";
cin>>odor;
niit_odor=odor;
for (int j=0; j<sar-1; j++)
niit_odor+=sariin_odruud[j];
cout<<"Jiliin ehnees ongorson odriin too : "<<niit_odor; }

(
.). :

Sariing oruulna uu (1 to 12):9


Odriig oruulna uu (1 to 31):9
Jiliin ehnees ongorson odriin too : 252
--------------------------------
Process exited after 4.778 seconds with return value 0
Press any key to continue . . .

,
, total_days .
days_per_month . : 5
4 (31, 28, 31, 30) .


.
.

, .

int days_per_month[]={31, 28, 31, 30, 31, 30,


31, 31, 30, 31, 30, 31};


0 .
.


. ,
.
.

#include <iostream>
using namespace std;
const int CITY = 2;
const int WEEK = 7;
int main()
{
int temperature[CITY][WEEK];
cout <<"Hoer hotiin agaariin temperaturiig oruul"<<endl;
// temperature massivd utgiig oruulj baina
for (int i = 0; i < CITY; ++i)
{
for(int j = 0; j < WEEK; ++j)
{
cout << "Hot " << i + 1 << ", Odor" << j + 1 << " : ";
cin >> temperature[i][j];
}

cout<<endl<<endl<<"Utgiig haruulj baina:"<<endl;

//temperature massiviin utguudad handaj baina


for (int i = 0; i < CITY; ++i)
{
for(int j = 0; j < WEEK; ++j)
{
cout << "Hot" << i + 1 << ", Odor " << j + 1 << " = " << temperature[i][j] <<
endl;
}
}

return 0;
}

temperature 2
.
Hoer hotiin agaariin temperaturiig oruul Utgiig haruulj baina:
Hot 1, Odor1 : 33 Hot1, Odor 1 = 33
Hot 1, Odor2 : 30 Hot1, Odor 2 = 30
Hot 1, Odor3 : 29 Hot1, Odor 3 = 29
Hot 1, Odor4 : 28 Hot1, Odor 4 = 28
Hot 1, Odor5 : 35 Hot1, Odor 5 = 35
Hot 1, Odor6 : 29 Hot1, Odor 6 = 29
Hot 1, Odor7 : 37 Hot1, Odor 7 = 37
Hot 2, Odor1 : -20 Hot2, Odor 1 = -20
Hot 2, Odor2 : -15 Hot2, Odor 2 = -15
Hot 2, Odor3 : -19 Hot2, Odor 3 = -19
Hot 2, Odor4 : -25 Hot2, Odor 4 = -25
Hot 2, Odor5 : -30 Hot2, Odor 5 = -30
Hot 2, Odor6 : -35 Hot2, Odor 6 = -35
Hot 2, Odor7 : -33 Hot2, Odor 7 = -33


.

int temperature[CITY][WEEK];

.
, temperature city week
. 3
.
2 .

temperature[i][j]

.
temperature[i][j] .

.

. saleinit .

#include <iostream>
using namespace std;
int main() {
// Ene massiv 12 hurtelh element hadgalna (2x3x2)
int test[2][3][2];
cout << "12 utgiig garaas oruulna uu:"<<endl;
// test massivd utgiig oruulj bn
// 3 davtaltiig ashiglah shaardalagatai
for(int i = 0; i < 2; ++i)
{
for (int j = 0; j < 3; ++j)
{
for(int k = 0; k < 2; ++k )
{
cin >> test[i][j][k];
}
}
}

cout<<endl<<"Displaying Value stored:"<<endl;

// delgetsend massiviin elementiin indeksiin daguu hevlej bna.


for(int i = 0; i < 2; ++i)
{
for (int j = 0; j < 3; ++j)
{
for(int k = 0; k < 2; ++k)
{
cout << "test[" << i << "][" << j << "][" << k << "] = " << test[i][j][k] << endl;
}
}
}

return 0;
}

12 utgiig garaas oruulna uu: Displaying Value stored:
1 test[0][0][0] = 1
2 test[0][0][1] = 2
3 test[0][1][0] = 3
4 test[0][1][1] = 4
5 test[0][2][0] = 5
6 test[0][2][1] = 6
7 test[1][0][0] = 7
8 test[1][0][1] = 8
9 test[1][1][0] = 9
10 test[1][1][1] = 10
11 test[1][2][0] = 11
12 test[1][2][1] = 12

--------------------------------
Process exited after 7.738 seconds with return value 0

2 .
. ,
, .

.

#include <iostream>
using namespace std;
void display(int marks[5]);
int main()
{
int marks[5] = {88, 76, 90, 61, 69};
display(marks);
return 0;
}
void display(int m[5])
{
cout << "Delgetsend temdeglegdsen "<< endl;

for (int i = 0; i < 5; ++i)


{
cout << "Oyutnuud "<< i + 1 <<": "<< m[i] << endl;
}
}

:

Delgetsend temdeglegdsen
Oyutnuud 1: 88
Oyutnuud 2: 76
Oyutnuud 3: 90
Oyutnuud 4: 61
Oyutnuud 5: 69

--------------------------------
Process exited after 0.01827 seconds with return value 0
Press any key to continue . . .

#include <iostream>
void display(int n[3][2])
using namespace std;
void display(int n[3][2]); {
int main()
{ cout << "Utguudiig haruullaa:" << endl;
int num[3][2] = { for(int i = 0; i < 3; ++i)
{3, 4}, {
{9, 5}, for(int j = 0; j < 2; ++j)
{7, 1} {
}; cout << n[i][j] << " ";
display(num); }
}
return 0;
}
}

:

Utguudiig haruullaa:
349571
--------------------------------
Process exited after 0.01901 seconds with return value 0
Press any key to continue . . .

do .
max 100 . 100-
?
.
.
,
. ,
.

.
do
.

If (n>=max)
{
cout << \n !!!;
break;
}


.
. C++- .
, .
randomize() .
stdlib.h, time.h 2 .
random()
.
. 0- 51-
random (52) .
,
.

#include <iostream>
using namespace std;

int main()
{
int i, n;
float arr[100];

cout << "Elementuudiig toog oruul (1-s 100 hoorond): ";


cin >> n;
cout << endl;

// Hereglegchiin oruulsan toog hadgalj baina
for(i = 0; i < n; ++i)
{
cout << "Toog oruul " << i + 1 << " : ";
cin >> arr[i];
}
//arr[0] massiviin hamgiin ih toog davtalt ashiglan hadgalj baina
for(i = 1;i < n; ++i)
{
// Hervee ta hamgiim baga massiviin elementiig olohiig husvel < temdegiig > bolgoh heregtei
if(arr[0] < arr[i])
arr[0] = arr[i];
}
cout << "Hamgiin ih element = " << arr[0];
return 0;
}


Elementuudiig toog oruul (1-s 100 hoorond): 15

Toog oruul 1 : 1
Toog oruul 2 : 2
Toog oruul 3 : 9
Toog oruul 4 : 66
Toog oruul 5 : 99
Toog oruul 6 : 100
Toog oruul 7 : 999
Toog oruul 8 : 5
Toog oruul 9 : 6666
Toog oruul 10 : 4897
Toog oruul 11 : 18886
Toog oruul 12 : 95
Toog oruul 13 : 1
Toog oruul 14 : -8
Toog oruul 15 : 5
Hamgiin ih element = 18886

1. ,
2. , 6- , , ,
,
3. U.CS101
4. he2must.blogspot.com
5. https://www.programiz.com/cpp-programming/multidimensional-arrays
6. https://www.programiz.com/cpp-programming/passing-arrays-function
7. https://www.programiz.com/cpp-programming/examples/array-largest-element

You might also like

  • Lecture 15
    Lecture 15
    Document40 pages
    Lecture 15
    Amarsaikhan Tuvshinbayar
    No ratings yet
  • Programming Lec 6
    Programming Lec 6
    Document51 pages
    Programming Lec 6
    Amarsaikhan Tuvshinbayar
    No ratings yet
  • Lec1-1 Corporate Activity Shine
    Lec1-1 Corporate Activity Shine
    Document61 pages
    Lec1-1 Corporate Activity Shine
    Amarsaikhan Tuvshinbayar
    0% (1)
  • Lecture 13
    Lecture 13
    Document46 pages
    Lecture 13
    Amarsaikhan Tuvshinbayar
    100% (2)
  • Lecture - 10
    Lecture - 10
    Document35 pages
    Lecture - 10
    Amarsaikhan Tuvshinbayar
    No ratings yet
  • Lecture 9
    Lecture 9
    Document46 pages
    Lecture 9
    Amarsaikhan Tuvshinbayar
    No ratings yet
  • Lecture 8 2018
    Lecture 8 2018
    Document54 pages
    Lecture 8 2018
    Amarsaikhan Tuvshinbayar
    100% (3)
  • Lecture 12
    Lecture 12
    Document34 pages
    Lecture 12
    Amarsaikhan Tuvshinbayar
    No ratings yet
  • Lecture 5 2018
    Lecture 5 2018
    Document54 pages
    Lecture 5 2018
    Amarsaikhan Tuvshinbayar
    100% (2)
  • Lecture 3 2018
    Lecture 3 2018
    Document42 pages
    Lecture 3 2018
    Amarsaikhan Tuvshinbayar
    No ratings yet
  • Lecture 2 2018
    Lecture 2 2018
    Document33 pages
    Lecture 2 2018
    Amarsaikhan Tuvshinbayar
    100% (1)
  • Lecture 11
    Lecture 11
    Document24 pages
    Lecture 11
    Amarsaikhan Tuvshinbayar
    100% (2)
  • Lecture 6 2018
    Lecture 6 2018
    Document50 pages
    Lecture 6 2018
    Amarsaikhan Tuvshinbayar
    100% (3)
  • Lecture 4 2018
    Lecture 4 2018
    Document47 pages
    Lecture 4 2018
    Amarsaikhan Tuvshinbayar
    100% (4)
  • Lecture 7 20108
    Lecture 7 20108
    Document47 pages
    Lecture 7 20108
    Amarsaikhan Tuvshinbayar
    75% (4)
  • IT101 Lecture 4
    IT101 Lecture 4
    Document72 pages
    IT101 Lecture 4
    Amarsaikhan Tuvshinbayar
    No ratings yet
  • Baikal Hotolbor
    Baikal Hotolbor
    Document2 pages
    Baikal Hotolbor
    Amarsaikhan Tuvshinbayar
    No ratings yet
  • Lecture 3
    Lecture 3
    Document72 pages
    Lecture 3
    Amarsaikhan Tuvshinbayar
    No ratings yet
  • Lecture 1 2018
    Lecture 1 2018
    Document39 pages
    Lecture 1 2018
    Amarsaikhan Tuvshinbayar
    100% (6)
  • Baikal Hotolbor
    Baikal Hotolbor
    Document2 pages
    Baikal Hotolbor
    Amarsaikhan Tuvshinbayar
    No ratings yet
  • Programming Lec 4
    Programming Lec 4
    Document39 pages
    Programming Lec 4
    Amarsaikhan Tuvshinbayar
    No ratings yet
  • Programming Lec 9
    Programming Lec 9
    Document39 pages
    Programming Lec 9
    Amarsaikhan Tuvshinbayar
    No ratings yet
  • Programming Lec 7
    Programming Lec 7
    Document57 pages
    Programming Lec 7
    Amarsaikhan Tuvshinbayar
    No ratings yet
  • Lecture 3
    Lecture 3
    Document72 pages
    Lecture 3
    Amarsaikhan Tuvshinbayar
    No ratings yet
  • Lecture 2
    Lecture 2
    Document80 pages
    Lecture 2
    Amarsaikhan Tuvshinbayar
    No ratings yet
  • Lecture 1
    Lecture 1
    Document54 pages
    Lecture 1
    Amarsaikhan Tuvshinbayar
    100% (2)
  • Programming Lec 8
    Programming Lec 8
    Document32 pages
    Programming Lec 8
    Amarsaikhan Tuvshinbayar
    100% (1)
  • Programming Lec 6
    Programming Lec 6
    Document51 pages
    Programming Lec 6
    Amarsaikhan Tuvshinbayar
    No ratings yet
  • PL - 3
    PL - 3
    Document47 pages
    PL - 3
    Amarsaikhan Tuvshinbayar
    No ratings yet
  • Koosen 2018 Algorithm Programming 3
    Koosen 2018 Algorithm Programming 3
    Document46 pages
    Koosen 2018 Algorithm Programming 3
    Amarsaikhan Tuvshinbayar
    100% (1)