You must Sign In to post a response.
  • Category: Windows

    Find error in the code

    public int GetDecimalPlaces(double accuracy)
    {
    return Math.Min(0, -(int)(Math.Floor(Math.Log10(accuracy))));
    }

    could you please tell me the error in above code
  • #764034
    what error you are getting can you please explain here and if you take a snapshot of that well and Good
    SRI RAMA PHANI BHUSHAN KAMBHAMPATI

  • #764035
    Got it thanks for the reply.Got one more question.

    Can you help me how to get sequence of numbers and find min and max with out using built in c# functions

  • #764039
    Hai Surya,
    There could be many ways to find the min and max number from the series of numbers.
    1. Use forloop: By using for loop, you can get the max number and min number from the array of numbers.

    static void Main(string[] args)
    {
    int[] arrNumbers = {2, 3, 1, 0, 8, 9, 5};
    var min = arrNumbers[0];
    var max = arrNumbers[0];
    for (int i = 0; i < arrNumbers.Length; i++)
    {
    if (arrNumbers[i] > max)
    max = arrNumbers[i];
    if (arrNumbers[i] < min)
    min = arrNumbers[i];
    }
    Console.WriteLine(min.ToString());
    Console.WriteLine(max.ToString());
    Console.ReadKey();
    }

    2. using foreach loop: By using foreach loop also we can get the min and max numbers.

    static void Main(string[] args)
    {
    int[] arrNumbers = {2, 3, 1, 0, 8, 9, 5};
    var min = arrNumbers[0];
    var max = arrNumbers[0];
    foreach (var value in arrNumbers)
    {
    if (value < min) min = value;
    if (value > max) max = value;
    }
    Console.WriteLine(min.ToString());
    Console.WriteLine(max.ToString());
    Console.ReadKey();
    }

    3. using Linq and Lambda expression:
    Using Linq:

    static void Main(string[] args)
    {
    int[] arrNumbers = {2, 3, 1, 0, 8, 9, 5};
    var min = (from number in arrNumbers
    orderby number ascending
    select number).First();
    var max = (from number in arrNumbers
    orderby number descending
    select number).First();
    Console.WriteLine(min.ToString());
    Console.WriteLine(max.ToString());
    Console.ReadKey();
    }

    Using lambda Expressions:

    static void Main(string[] args)
    {
    int[] arrNumbers = {2, 3, 1, 0, 8, 9, 5};
    var min = arrNumbers.OrderBy(x=>x).First();
    var max = arrNumbers.OrderBy(x => x).Last();
    Console.WriteLine(min.ToString());
    Console.WriteLine(max.ToString());
    Console.ReadKey();
    }

    Hope it will be helpful to you.

    Regards,
    Pawan Awasthi(DNS MVM)
    +91 8123489140 (whatsApp), +60 14365 1476(Malaysia)
    pawansoftit@gmail.com


Sign In to post your comments