using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Array_2
{
    class Program
    {
        static void Main()
        {
            int i;
            int[] c=new int[11];
            int[] b=new int[11];
            int[] a=new int[11];
            for ( i = 0; i <= 10; i++)
           
                //Console.WriteLine("Enter a Matrix1");
                a[i] = Console.Read();
           
            for ( i = 0; i <= 10; i++)
           
                //Console.WriteLine("Enter  a Matrix2");

                b[i] = Console.Read();
           
            for (i = 0; i <= 10; i++)
           
                c[i] = a[i] + b[i];
           
           
                Console.WriteLine("The Addtion of Two Matrix is = {0}", c[i]);
           
            Console.Read();
        }
    }
}

Edited 6 Years Ago by Nick Evan: Added code-tags

hi!

First of all: what do you mean with matrix? For me, a matrix is int [][] and not int [] (this is for me a vector).

And in this line: this is only the addition of two values from the vector.

for (i = 0; i <= 10; i++)
c = a + b;

In this line, the value of "i" is 11 and your array is of a shorter dimension!!

Console.WriteLine("The Addtion of Two Matrix is = {0}", c);

By the way, if you want to make an output of the whole vector, this must be also inside the for-loop

for (i = 0; i <= 10; i++)
{
    c[i] = a[i] + b[i];
    Console.WriteLine("The Addtion of Row{0} is = {1}",i, c[i]);
}

Daniel

Edited 6 Years Ago by DanielGreen: n/a

As DanielGreen said, i think there is some confusion about the meaning of a matrix. You are adding together two arrays.
Also, you have not enclosed your for loops in bracers. Unless you have a single line of code it is best to use bracers to ensure the correct code runs inside the loop.
Try this:

int i;
            int[] c = new int[11];
            int[] b = new int[11];
            int[] a = new int[11];
            for (i = 0; i < 10; i++)
            {
                Console.WriteLine("Enter next digit for Matrix 1"); 
                //try converting to int, request new input if value not valid
                while(!int.TryParse(Console.ReadLine(), out a[i]))
                {
                    Console.WriteLine("Please enter only numbers");
                }
            }
            for (i = 0; i < 10; i++)
            {
                Console.WriteLine("Enter next digit for Matrix 2");
                while (!int.TryParse(Console.ReadLine(), out b[i]))
                {
                    Console.WriteLine("Please enter only numbers");
                }
            }
            for (i = 0; i < 10; i++)
            {
                c[i] = a[i] + b[i];
                Console.WriteLine("The Addtion of Two Matrix at position {1} is = {0}", c[i], i);
            }
            Console.ReadKey();
This article has been dead for over six months. Start a new discussion instead.