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 ConsoleApplication6
- {
- class Program
- {
- static void Main(string[] args)
- {
- int[] newarray = new int[10];
- int count = 0;
- Random rand = new Random();
- while (count < 10)
- {
- int num = rand.Next(10) + 1;
- newarray[count] = num;
- count++;
- }
- //creates array
- Console.WriteLine("Printing array...");
- count = 0;
- while (count < newarray.Length)
- {
- Console.WriteLine(newarray[count]);
- count++;
- }
- Console.WriteLine("Done!\n\n");
- halfcomparer(newarray);
- }
- static void halfcomparer(int[] array)
- {
- int sum1 = 0, sum2 = 0;
- int count = 0;
- while (count < (array.Length / 2))
- {
- sum1 = sum1 + array[count];
- count++;
- }
- Console.WriteLine("The first half's total is: " + sum1);
- count = 0;
- while (count < array.Length)
- {
- sum2 = sum2 + array[count];
- count++;
- }
- sum2 = sum2 - sum1;
- Console.WriteLine("The second half's total is: " + sum2);
- if (sum1 > sum2)
- {
- Console.WriteLine("The first half's sum is bigger");
- }
- else if (sum1 < sum2)
- {
- Console.WriteLine("The second half's sum is bigger");
- }
- else if (sum1 == sum2)
- {
- Console.WriteLine("Both halves are equal");
- }
- Console.ReadKey();
- ;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement