0

I am trying to return the integer array element after finding the 3 consecutive number problem please tell me where i am going wrong to return the array element inside from the loop.i want to return value in array and catch that element in another array.

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

namespace interview
{
class Program
{
    static void Main(string[] args)
    {
        int[] arr = new int[5]{1,3,4,5,5};
        int[] arr1 = GetOriginalScore(3,arr);
        for (int i = 0; i < arr1.Length; i++)
        {
            Console.WriteLine(arr1[i]);
        }
    }
    public static int[] GetOriginalScore(int input1, int[] input2)
    {

        for (int i = 0; i < input1; i++)
        {
            int a=((3 * input2[i] + 3) / 3);
            if (a == (input2[i] + 1))
            {
                return  input2[i];
            }

        }
    }
}
}
1
  • 2
    please tell me where i am going to wrong didn't the compiler tell you something as well? Or in what way do your expected results differ from the actual ones? Commented Apr 10, 2014 at 12:48

2 Answers 2

4
public static int[] GetOriginalScore(int input1, int[] input2)

here, you specify that you want to return an array. If you want to return an element:

public static int GetOriginalScore(int input1, int[] input2)
Sign up to request clarification or add additional context in comments.

2 Comments

but i want to return in array
Then you might want to mark the array as an out parameter. Or rewrite your question and tell us what you want to accomplish.
1

You need to change the code from,

public static int[] GetOriginalScore(int input1, int[] input2)

to

public static int GetOriginalScore(int input1, int[] input2)

The function will look like this

public static int GetOriginalScore(int input1, int[] input2)
    {

        for (int i = 0; i < input1; i++)
        {
            int a=((3 * input2[i] + 3) / 3);
            if (a == (input2[i] + 1))
            {
                return  input2[i];
            }
            else
            {
                return 0;
            }
        }
    }

2 Comments

@DrCopyPaste You should have checked properly!
True, but you could also have commented your answer in the first place, too ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.