VINAY KUMAR GUPTA
3.Write a program to find out the how many 9 is present in given input eg:100 to 10000 ?
By VINAY KUMAR GUPTA in Algorithms in C# on Sep 07 2015
  • VenkateswaraRao N
    Jun, 2021 13

    1. public static int FindNumberCount(int lowerIndex, int upperIndex, char toMatch)
    2. {
    3. var count = Enumerable.Range(lowerIndex, upperIndex).Sum(x =>
    4. {
    5. return x.ToString().ToCharArray().Count(y => y == toMatch);
    6. });
    7. return count;
    8. }

    • 2
  • Aman Patel
    Sep, 2019 19

    int count = 0;
    for (int i=100;i<=10000;i++)
    {
    char[] number = i.ToString().ToCharArray();
    for (int j=0;j<number.Length;j++)
    {
    // Console.WriteLine(number[j]);
    if (number[j].ToString() == “9”)
    count++;
    }

    }
    Console.Write(count); //3980

    • 0
  • sanjay lalwani
    May, 2018 1

    --Loop this function for every number from 100 to 10000static void ConvertToInt(Int32 iNum, int iNoToFind,ref int iCnt){ Int32 iDig = Convert.ToInt32(Math.Floor(Math.Log10(iNum)));Int32 iDiv =Convert.ToInt32(Math.Pow(10, iDig));if(iNum/iDiv ==iNoToFind){iCnt++; }if(iNum/10 > 0 && iNum%iDiv > 0)ConvertToInt( iNum%iDiv, iNoToFind, ref iCnt);}

    • 0
  • Sai Kirat
    Sep, 2016 6

    --looped in SQL, can be done similarly in c# as well declare @min int = 0,@max int=100,@ctr int =0,@nines int = 0,@str nvarchar(10)=''while (@min<=@max) Begin set @str = convert(nvarchar(10),@min) set @nines = @nines + (len(@str)-len(replace(@str,'9',''))) set @min=@min+1 End select @nines

    • 0
  • VINAY KUMAR GUPTA
    May, 2016 12

    public static void Main() { int a = 100; int b = 10000; int count = 0; int c = 0; int x = 0; for (int i = a; i <= b; i++) { c = i; while (c != 0) { x = c % 10; c = c / 10; if (x == 9) { count++; } } } Console.WriteLine(count); }

    • 0
  • VINAY KUMAR GUPTA
    Sep, 2015 7

    public static void Main() {int a = 100;int b = 10000;int count = 0;int c = 0;int x = 0;for (int i = a; i <= b; i++){c = i;while (c != 0){x = c % 10;c = c / 10;if (x == 9){count++;}}}Console.WriteLine(count); }

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS