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;
- using System.Threading.Tasks;
- namespace _2015_C_sharp_Exam
- {
- class Program
- {
- /*
- arrays are passed to methods by reference that
- means that the actual values in the array will
- change, not just in the method, so I created a new
- array called copy, and copied the values of the
- array to it, because I don't want the default values
- of the array to change because it will be used later
- in another method ( SubtractTen() )
- */
- static void MultiblyByFive(int[] arr)
- {
- int[] copy = new int[arr.Length];
- for (int i = 0; i < arr.Length; i++)
- {
- Console.Write(arr[i] + " ");
- copy[i] = arr[i];
- }
- for (int i = 0; i < copy.Length; i++)
- {
- copy[i] *= 5; //arr[i] = arr[i] * 5;
- }
- Console.WriteLine();
- for (int i = 0; i < arr.Length; i++)
- {
- Console.Write(copy[i] + " ");
- }
- Console.WriteLine();
- }
- static void SubtractTen(int[] arr)
- {
- Console.WriteLine(arr[2]);
- arr[2] -= 10;
- Console.WriteLine(arr[2]);
- }
- static void Main(string[] args)
- {
- //Question 3 - b
- Console.Write("Enter the size of the array : ");
- int size = int.Parse(Console.ReadLine());
- int[] arr = new int[size];
- Console.WriteLine("Enter the array elements : ");
- for (int i = 0; i < size; i++)
- {
- arr[i] = int.Parse(Console.ReadLine());
- }
- Console.WriteLine("Default array and after multiblying by five : ");
- MultiblyByFive(arr);
- Console.WriteLine("Default third element value and after subtracting 10 :");
- SubtractTen(arr);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement