Advertisement
haquaa

Untitled

May 26th, 2016
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.15 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _2015_C_sharp_Exam
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             //Question 2 - a
  14.  
  15.             int[] arr = { 12, 6, 13, 4, 9, 5 };
  16.  
  17.             int DivByThree = 0;
  18.             for (int i = 0; i < arr.Length; i++)
  19.             {
  20.                 if (arr[i] % 3 == 0)
  21.                 {
  22.                     DivByThree++;
  23.                 }
  24.             }
  25.  
  26.             Console.WriteLine("Numbers divisible by 3 = " + DivByThree);
  27.  
  28.             int maxNum = arr[0];
  29.             for (int i = 1; i < arr.Length; i++)
  30.             {
  31.                 if (arr[i] > maxNum)
  32.                 {
  33.                     maxNum = arr[i];
  34.                 }
  35.             }
  36.  
  37.             Console.WriteLine("Maximum number = " + maxNum);
  38.  
  39.             //swapping first and last element.
  40.             int temp = arr[0];
  41.             arr[0] = arr[5];
  42.             arr[5] = temp;
  43.  
  44.             Console.Write("First and last element after swaping : " + arr[0] + " " + arr[5] + "\n");
  45.         }
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement