locked
Generate 20 Floating Numbers programmatically in the following Pattern; like 12.34, 34.56, 56.78, 78.910, 910.1112, 1112.1314, RRS feed

  • Question

  • User-2107098468 posted

    Generate 20 Floating Numbers programmatically in the following Pattern; like 12.34, 34.56, 56.78, 78.910, 910.1112, 1112.1314, ... Please generate numbers with the starting number 12.34 and generate other numbers. Put the generated floating number into an array. Split the array into two arrays. Reverse the two arrays and print these arrays. Sum of the array elements and print the summation number. Please do not use strings and any string concatenation techniques, please generate the numbers in c#

    Monday, June 1, 2020 8:53 AM

All replies

  • User753101303 posted

    Hi,

    Looks like homework. IMO you'll learn more by trying (and failing which is part of the learning process) rather than by asking someone to do that for you. For a start if you look at the pattern you'll see it uses numbers from 1 to 14 and so you likey have to start with a loop to process 2 consecutive numbers and then have a formula to have them falling at their expected places.

    Edit : or according to "Please generate numbers with the starting number 12.34" the next number should be generated from the previous one.

    Monday, June 1, 2020 9:10 AM
  • User1535942433 posted

    Hi myselfvinay,

    Accroding to your description,as far as I think,you could calculate the number of digits for each digit.After you get these result,you could push in an array.

    Just like this:

    double resultint = 0;
                for (int i = 1; i < 20; i += 2)
                {
                    if (i <= 5)
                    {
                        resultint = i * 1000 + (i + 1) * 100 + (i + 2) * 10 + (i + 3);
                        Console.Write(resultint / 100);
                        Console.ReadKey();
                    }
                    else if (i >= 7 && i < 9)
                    {
                        resultint = i * 10000 + (i + 1) * 1000 + (i + 2) * 100 + (i + 3);
                        Console.Write(Convert.ToDecimal((resultint / 1000).ToString("f3")));
                        Console.ReadKey();
                    }
                    else if (i >= 9 && i < 11)
                    {
                        resultint = i * 1000000 + (i + 1) * 10000 + (i + 2) * 100 + (i + 3);
                        Console.Write(resultint / 10000);
                        Console.ReadKey();
                    }
                    else
                    {
                        resultint = i * 1000000 + (i + 1) * 10000 + (i + 2) * 100 + (i + 3);
                        Console.Write(resultint / 10000);
                        Console.ReadKey();
                    }
    
                }

    Result:

    Best regards,

    Yijing Sun

    Tuesday, June 2, 2020 3:01 AM