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
- {
- static void Main(string[] args)
- {
- //Question 2 - a
- int[] arr = { 12, 6, 13, 4, 9, 5 };
- int DivByThree = 0;
- for (int i = 0; i < arr.Length; i++)
- {
- if (arr[i] % 3 == 0)
- {
- DivByThree++;
- }
- }
- Console.WriteLine("Numbers divisible by 3 = " + DivByThree);
- int maxNum = arr[0];
- for (int i = 1; i < arr.Length; i++)
- {
- if (arr[i] > maxNum)
- {
- maxNum = arr[i];
- }
- }
- Console.WriteLine("Maximum number = " + maxNum);
- //swapping first and last element.
- int temp = arr[0];
- arr[0] = arr[5];
- arr[5] = temp;
- Console.Write("First and last element after swaping : " + arr[0] + " " + arr[5] + "\n");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement