Advertisement
WadeRollins2710

C# Array Example

Jul 3rd, 2016
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.83 KB | None | 0 0
  1. //C Sharp Array Example [Incomplete]
  2. using System;
  3.  
  4. namespace ConsoleApplicationArrayCSharp
  5. {
  6.     class Program
  7.     {
  8.         public static class Globals
  9.         {
  10.             public static int n;
  11.             public static int[] A = new int[100];
  12.         }
  13.         static void Input()
  14.         {
  15.             Console.Write("Input the number of the element: ");
  16.             Globals.n = int.Parse(Console.ReadLine());
  17.             for (int i=1;i<=Globals.n;i++)
  18.             {
  19.                 Console.Write("Input A[{0}]: ", i);
  20.                 Globals.A[i] = int.Parse(Console.ReadLine());
  21.             }
  22.         }
  23.  
  24.         static void Output()
  25.         {
  26.             for (int i = 1; i <= Globals.n; i++)
  27.                 Console.Write("{0} ", Globals.A[i]);
  28.             Console.WriteLine();
  29.         }
  30.  
  31.         static void Find_Prime_Number()
  32.         {
  33.             Console.Write("Prime Number: ");
  34.             int count = 0;
  35.             for (int i=1;i<=Globals.n;i++)
  36.             {
  37.                 int c = 0;
  38.                 for (int j=2;j<=Globals.A[i]/2;j++)
  39.                     if (Globals.A[i]%j==0)
  40.                     {
  41.                         c = 1;
  42.                         break;
  43.                     }
  44.                 if (Globals.A[i] == 1) c = 1;
  45.                 if (c==0)
  46.                 {
  47.                     count++;
  48.                     Console.Write("{0} ", Globals.A[i]);
  49.                 }
  50.             }
  51.             if (count == 0) Console.Write("None!");
  52.             Console.WriteLine();
  53.         }
  54.  
  55.         static void Find_Square_Number()
  56.         {
  57.             Console.Write("Square Number: ");
  58.             int count = 0;
  59.             for (int i = 1; i <= Globals.n; i++)
  60.             {
  61.                 if (Math.Sqrt(Globals.A[i])*Math.Sqrt(Globals.A[i])==Globals.A[i])
  62.                 {
  63.                     count++;
  64.                     Console.Write("{0} ", Globals.A[i]);
  65.                 }
  66.             }
  67.             if (count == 0) Console.Write("None!");
  68.             Console.WriteLine();
  69.         }
  70.  
  71.         static void Find_Perfect_Number()
  72.         {
  73.             Console.Write("Perfect Number: ");
  74.             int count = 0;
  75.             for (int i = 1; i <= Globals.n; i++)
  76.             {
  77.                 int S = 0;
  78.                 for (int j=1;j<=Globals.A[i];j++)
  79.                 if (Globals.A[i]%j==0)
  80.                     S = S + j;
  81.                 if (S==Globals.A[i])
  82.                 {
  83.                     count++;
  84.                     Console.Write("{0} ", Globals.A[i]);
  85.                 }
  86.             }
  87.             if (count == 0) Console.Write("None!");
  88.             Console.WriteLine();
  89.         }
  90.  
  91.         static void Quick_Sort(int head, int end)
  92.         {
  93.             lock
  94.         }
  95.  
  96.         static void Insert()
  97.         {
  98.             Console.Write("Input position to insert: ");
  99.             int Pos = int.Parse(Console.ReadLine());
  100.             Console.Write("Input value: ");
  101.             int Val = int.Parse(Console.ReadLine());
  102.             Globals.n++;
  103.             for (int i = Globals.n; i >= Pos; i--)
  104.                 Globals.A[i] = Globals.A[i - 1];
  105.             Globals.A[Pos] = Val;
  106.         }
  107.  
  108.         static void Remove()
  109.         {
  110.             Console.Write("Input position to remove: ");
  111.             int Pos = int.Parse(Console.ReadLine());
  112.             Globals.n--;
  113.             for (int i = Pos; i <= Globals.n; i++)
  114.                 Globals.A[i] = Globals.A[i + 1];
  115.         }
  116.  
  117.         static public void Main(string[] args)
  118.         {
  119.             int[] A = new int[100];
  120.             Console.Clear();
  121.             Input();
  122.             Output();
  123.             Find_Prime_Number();
  124.             Find_Square_Number();
  125.             Find_Perfect_Number();
  126.             Quick_Sort(1,n);
  127.             Insert();
  128.             Remove();
  129.             Console.ReadLine();
  130.         }
  131.     }
  132. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement