Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ConsoleApplication24.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <iostream>
- #include <conio.h>
- using namespace std;
- void Max(int &iMax, int a[], int n)
- {
- iMax = a[1];
- for (int i = 2; i <= n; i++)
- {
- if (iMax < a[i]) iMax = a[i];
- }
- }
- void Min(int &iMin, int a[], int n)
- {
- iMin = a[1];
- for (int i = 2; i <= n; i++)
- {
- if (iMin > a[i]) iMin = a[i];
- }
- }
- void Sum(int a[], int n, int &sum)
- {
- sum = 0;
- for (int i = 1; i <= n; i++)
- {
- sum += a[i];
- }
- }
- void main()
- {
- int a[50], n, i, iMax, iMin, sum, pIck;
- cout << "bam 1 de nhap mang: ";
- cin >> pIck;
- if (pIck == 1)
- {
- cout << "nhap so luong phan tu cua mang: ";
- cin >> n;
- while (n <= 0)
- {
- cout << "nhap lai so luong phan tu cua mang: ";
- cin >> n;
- }
- for (i = 1; i <= n; i++)
- {
- cout << "nhap phan tu cua mang: ";
- cin >> a[i];
- }
- cout << "nhap 2 de tim phan tu lon nhat, 3 de tim phan tu nho nhat, 4 de tinh tong cac phan tu ";
- cin >> pIck;
- if (pIck == 2)
- {
- Max(iMax, a, n);
- cout << iMax << endl;
- }
- if (pIck == 3)
- {
- Min(iMin, a, n);
- cout << iMin << endl;
- }
- }
- if (pIck == 4)
- {
- Sum(a, n, sum);
- cout << sum;
- }
- _getch();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement