Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Need a coding pattern to achieve

I am working on a C# program where I need certain numbers for formatting a printable string. This will help me in determining on how many /r/n I need to add between different datasets internally.

It is in WinForms.

public int GiveMeOutput(int input)
{
    int output = 2;

    //logic here

    return output;
}

Can anyone help me in any language for the logic?
Greatly appreciate your help.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I would be getting the input into a Function(int input) & it should throw the "int" output.

Below is the table I want

Input Output
5 2
6 2
7 3
8 3
9 4
10 4
11 5
12 5
13 6
14 6
…continues …continues

>Solution :

This should do the trick:

int Map(int input)
{
    return (input - 2 + input % 2) / 2;
}

Subtract 2, add 1 to odd numbers, then divide by 2.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading