-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathArraySum.cs
More file actions
22 lines (20 loc) · 760 Bytes
/
ArraySum.cs
File metadata and controls
22 lines (20 loc) · 760 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
namespace HackerRank //namespace is like a package in Java
{
public class ArraySum
{
public static void Main(string[] args)
{
int size = int.Parse(System.Console.ReadLine()); //reads in data from user then converts to integer
int[] array = new int[size];
int total = 0;
/* take the elements of the array inputted from the user and then convert those values to integer and then
put them into the integer array
*/
array = System.Array.ConvertAll(System.Console.ReadLine().Split(' '), int.Parse);
foreach (int cur in array) //for each loop
total += cur;
System.Console.WriteLine(total);
System.Console.ReadKey();
}
}
}