Skip to content

Summation Of indexes in arrays.

Ankit Kumar

Ankit Kumar

Asked Oct 15, 2015, 11:18 PM EDT1 answer
Share
LinkedInX
Hey all,
             I am having a problem with summation of two array's indexes.
             My requirement is as follow:-
             I have declared 3 arrays and i accepted values in two arrays from user.
             now i am adding the indexes of both of the arrays having values and putting the values in                      third array but however its not giving desired result:-
             i have attached the code file as code.zip 

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    Hi Ankit,
     
    you code is write but there was a typo error
     
    in second look it should be array2[i] not array[1] 
     
    C#
    static void Main(string[] args)
            {
                int[]array1= new int [5];
                int[]array2= new int[5];
                int[]array3=new int[5];
                Console.WriteLine(" enter Elements of Array1.");
                for (int i = 0; i < 5; i++)
                {
                    array1[i] = Convert.ToInt32(Console.ReadLine());
                }
                Console.WriteLine("enter elements of array2.");
                for (int i = 0; i < 5; i++)
                {
                    array2[i] = Convert.ToInt32(Console.ReadLine());
                }
                for (int i = 0; i < 5; i++)
                {
                    array3[i] = array1[i] + array2[i];
                }
                for (int j = 0; j < 5; j++)
                {
                    Console.WriteLine(array3[j]);
                }
    
                Console.ReadLine();
            }
     
     Please run code and verify.
    0