Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //C Sharp Array Example [Incomplete]
- using System;
- namespace ConsoleApplicationArrayCSharp
- {
- class Program
- {
- public static class Globals
- {
- public static int n;
- public static int[] A = new int[100];
- }
- static void Input()
- {
- Console.Write("Input the number of the element: ");
- Globals.n = int.Parse(Console.ReadLine());
- for (int i=1;i<=Globals.n;i++)
- {
- Console.Write("Input A[{0}]: ", i);
- Globals.A[i] = int.Parse(Console.ReadLine());
- }
- }
- static void Output()
- {
- for (int i = 1; i <= Globals.n; i++)
- Console.Write("{0} ", Globals.A[i]);
- Console.WriteLine();
- }
- static void Find_Prime_Number()
- {
- Console.Write("Prime Number: ");
- int count = 0;
- for (int i=1;i<=Globals.n;i++)
- {
- int c = 0;
- for (int j=2;j<=Globals.A[i]/2;j++)
- if (Globals.A[i]%j==0)
- {
- c = 1;
- break;
- }
- if (Globals.A[i] == 1) c = 1;
- if (c==0)
- {
- count++;
- Console.Write("{0} ", Globals.A[i]);
- }
- }
- if (count == 0) Console.Write("None!");
- Console.WriteLine();
- }
- static void Find_Square_Number()
- {
- Console.Write("Square Number: ");
- int count = 0;
- for (int i = 1; i <= Globals.n; i++)
- {
- if (Math.Sqrt(Globals.A[i])*Math.Sqrt(Globals.A[i])==Globals.A[i])
- {
- count++;
- Console.Write("{0} ", Globals.A[i]);
- }
- }
- if (count == 0) Console.Write("None!");
- Console.WriteLine();
- }
- static void Find_Perfect_Number()
- {
- Console.Write("Perfect Number: ");
- int count = 0;
- for (int i = 1; i <= Globals.n; i++)
- {
- int S = 0;
- for (int j=1;j<=Globals.A[i];j++)
- if (Globals.A[i]%j==0)
- S = S + j;
- if (S==Globals.A[i])
- {
- count++;
- Console.Write("{0} ", Globals.A[i]);
- }
- }
- if (count == 0) Console.Write("None!");
- Console.WriteLine();
- }
- static void Quick_Sort(int head, int end)
- {
- lock
- }
- static void Insert()
- {
- Console.Write("Input position to insert: ");
- int Pos = int.Parse(Console.ReadLine());
- Console.Write("Input value: ");
- int Val = int.Parse(Console.ReadLine());
- Globals.n++;
- for (int i = Globals.n; i >= Pos; i--)
- Globals.A[i] = Globals.A[i - 1];
- Globals.A[Pos] = Val;
- }
- static void Remove()
- {
- Console.Write("Input position to remove: ");
- int Pos = int.Parse(Console.ReadLine());
- Globals.n--;
- for (int i = Pos; i <= Globals.n; i++)
- Globals.A[i] = Globals.A[i + 1];
- }
- static public void Main(string[] args)
- {
- int[] A = new int[100];
- Console.Clear();
- Input();
- Output();
- Find_Prime_Number();
- Find_Square_Number();
- Find_Perfect_Number();
- Quick_Sort(1,n);
- Insert();
- Remove();
- Console.ReadLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement