View Single Post
  #1  
Old 17-06-2011, 08:59 PM
thecool's Avatar
thecool thecool is offline
Senior Member


 
Join Date: Apr 2009
Location: Multan
Posts: 1,163
Contact Number: Push me a PM if you really need
Program / Discipline: Alumni
Class Roll Number: ---
thecool has a reputation beyond reputethecool has a reputation beyond reputethecool has a reputation beyond reputethecool has a reputation beyond reputethecool has a reputation beyond reputethecool has a reputation beyond reputethecool has a reputation beyond reputethecool has a reputation beyond reputethecool has a reputation beyond reputethecool has a reputation beyond reputethecool has a reputation beyond repute
Lightbulb Array program in C sharp

Code:
using System;
using System.Collections.Generic;
using System.Text;

namespace array_2d
{
class Program
{
static void Main(string[] args)
{
int[,] mat = new int[3, 3];
int i, j,sum=0;

Console.WriteLine("Enter 9 elements:");
for (i = 0; i < 3; i++)
{
for (j = 0; j < 3; j++)
{
Console.WriteLine("Enter element:");
mat[i, j] = Convert.ToInt16(Console.ReadLine());
}
}

Console.WriteLine("\nThe array entered is:\n");
for (i = 0; i < 3; i++)
{
for (j = 0; j < 3; j++)
Console.Write(mat[i, j]+"\t");

Console.WriteLine("\n");
}

Console.WriteLine("The sum of array elments is:");
for (i = 0; i < 3; i++)
{
for (j = 0; j < 3; j++)
sum=sum + mat[i, j];
}
Console.WriteLine(sum);

Console.ReadLine();
}
}
}

Reply With Quote