Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- //CHU' Y' !!!!
- namespace Mang1Chieu //mo^~i sinh vien viet code hoan chinh bai` nay` roi nop vao` dia chi email votandung@yahoo.com
- {
- class Mang
- {
- private int[] a;
- private int n;
- public Mang()
- {
- n = 0;
- a = new int[n];
- }
- public Mang(int nn)
- {
- Random rd = new Random();
- n = nn;
- a = new int[n];
- for (int i = 0; i < n; i++)
- {
- a[i] = rd.Next(-10,10);
- }
- }
- public Mang(Mang arr)
- {
- n = arr.n;
- a = new int[n];
- for (int i = 0; i < n; i++)
- {
- a[i] = arr.a[i];
- }
- }
- public Mang(int []aa, int nn)
- {
- n = nn;
- a = new int[n];
- for (int i = 0; i < n; i++)
- {
- a[i] = aa[i];
- }
- }
- public override string ToString()
- {
- string s="[";
- for (int i = 0; i < n-1; i++)
- {
- s = s + a[i] + " ";
- }
- s = s + "]";
- return s;
- }
- public int N
- {
- get { return this.n; }
- set { if (value > 0) this.n = value; }
- }
- public int[] A
- {
- get { return this.a; }
- set { this.a = value; }
- }
- public Mang Cong(Mang arr)
- {
- Mang tam=new Mang();
- int n;
- if (this.N > arr.N)
- n = arr.n;
- else
- n = this.n;
- tam.N = n;
- for (int i = 0; i < n; i++)
- tam.a[i] = this.a[i] + arr.a[i];
- return tam; //phai sua lai cho dung
- }
- public Mang Cong(Mang arr1, Mang arr2)
- {
- Mang tam = new Mang();
- if (arr1.N > arr2.N)
- tam.N = arr2.N = arr1.N;
- else
- tam.N = arr1.N = arr2.N;
- for (int i = 0; i < tam.N; i++)
- tam.a[i] = arr1.A[i] + arr2.A[i];
- return tam; //phai sua lai cho dung
- }
- public int TimViTriMax()
- {
- int pos=0;
- for (int i = 0; i < this.n; i++)
- if (this.a[pos] < this.a[i])
- pos = i;
- return pos;
- }
- public int TimViTriMax(Mang arr)
- {
- int pos = 0;
- for (int i = 0; i < arr.N; i++)
- if (arr.A[pos] < arr.A[i])
- pos = i;
- return pos;
- }
- public int TongMang()
- {
- int sum=0;
- for (int i = 0; i < this.n; i++)
- sum += this.a[i];
- return sum;
- }
- public int TimViTriMin()
- {
- int pos = 0;
- for (int i = 0; i < this.n; i++)
- if (this.a[pos] > this.a[i])
- pos = i;
- return pos;
- }
- public int TimViTriMin(Mang arr)
- {
- int pos = 0;
- for (int i = 0; i < arr.N; i++)
- if (arr.A[pos] > arr.A[i])
- pos = i;
- return pos;
- }
- public int TongMang(Mang arr)
- {
- int sum = 0;
- for (int i = 0; i < arr.N; i++)
- sum += arr.A[i];
- return sum;
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- Mang a, b, c;
- a = new Mang();
- b = new Mang(4);
- int[] p = { 1, 2, 3, 4, 5 };
- c = new Mang(p, 5);
- Console.WriteLine(b.Cong(c));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement