Hello guys.
I've seen another thread with this name but it was in C i'm interested to do it in C#
okay the program
how I can add the digits of a number. Could you give me an idea?
I have source, but i need another source with the same function!
here is my source
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication17
{
class Program
{
static void Main(string[] args) {
Random r = new Random();
int[] y = new int[10];
int[] x = new int[10];
for (int i = 0; i < y.Length; i++)
{
y[i] = r.Next(100);
Console.WriteLine(y[i]);
}
Console.WriteLine();
for (int i = 0; i < x.Length; i++)
{
x[i] = r.Next(100);
Console.WriteLine(x[i]);
}
Console.WriteLine();
Sum(y);
Sum(x);
Console.ReadKey();
}
static void Sum(int[] x) {
int sum = 0;
for (int i = 0; i < x.Length; i++)
{
sum += x[i];
}
Console.WriteLine("Sum = " + sum);
}
}
}