Here's an example of using a for loop to find the sum of an array of integers in C#:
main.cs174 chars10 lines
In this example, we create an integer array called numbers
with five elements. We also create an integer variable called sum
and initialize it to 0.
Then, we use a for loop to iterate through the numbers
array. For each element, we add its value to the sum
variable.
Finally, we print out the total sum using the Console.WriteLine
method.
This code will output: The sum of the numbers is: 15
gistlibby LogSnag