In C#, please.
Create a program that will accept 25 inputs into integer array Task2DArray and
compute for the sum and difference of all the elements.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp2
{
class Program
{
static void Main(string[] args)
{
// Create a program that will accept 25 inputs into integer array Task2DArray and compute for the sum and difference of all the elements.
int[,] arr= new int[6,6];
int diff = 0;
int sum = 0;
for (int i = 0; i < arr.GetLength(0); i++)
{
for (int j = 0; j < arr.GetLength(1); j++)
{
Console.WriteLine("Input [{0}, {1}] number :", i + 1, j + 1);
arr[i, j] = Convert.ToInt32(Console.ReadLine());
}
}
for (int i = 0; i < arr.GetLength(0); i++)
{
for (int j = 0; j < arr.GetLength(1); j++)
{
sum = sum + arr[i, j];
diff = diff - arr[i, j];
}
}
Console.WriteLine("Sum: {0}", sum);
Console.WriteLine("Diff: {0}", diff);
Console.ReadKey();
}
}
}
Comments
Leave a comment