Answer the question
In order to leave comments, you need to log in
How can I find the sum of the digits of each element of an array using a For loop?
Given an array, any. For example, from 1 to 1000. You need to find the sum of the digits of its each element, but with a for loop, it might sound silly
Answer the question
In order to leave comments, you need to log in
int[] arr = new int[] { 1, 2, 3 };
int sum = 0;
//Две различные вариации.
//Через foreach
foreach (var item in arr)
{
sum += item;
}
//
//Если через просто for
for(int i = 0;i<arr.Length;i++)
{
sum+=arr[i];
}
//
Console.WriteLine(sum);
int[] Array = new int[] { 1, 2, 3, 4 }; //declaring an array
for(int i = 0;i< Array.Length; i++)
{
Console.WriteLine($"element # {Array[i]}"); // output to the Console of all elements separately
}
int i=0;
int[]mas=new int[];
for(int l=0;l<mas.Lenght;l++)
i+=mas[l];
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question