Armstrong Number Program in C#.Net || C# Interview Program

Поделиться
HTML-код
  • Опубликовано: 16 ноя 2024

Комментарии • 15

  • @technicalnileshrathod.579
    @technicalnileshrathod.579 2 месяца назад

    ... Easiest way ever .....good sir.

  • @sainath2983
    @sainath2983 8 месяцев назад +2

    public static void Main(string[] args)
    {
    int r, sum = 0, count = 0,rem;
    Console.WriteLine("Enter a number");
    int num = Convert.ToInt32(Console.ReadLine());
    int x = num;
    while (x > 0)
    {
    r = x % 10;
    count++;
    x = x / 10;
    }
    while (num > 0)
    {
    rem = num % 10;
    sum = sum + ((int)Math.Pow(rem, count));
    num = num / 10;
    }
    Console.WriteLine("Armstrong number = {0}",sum);
    }

  • @deekshadubey6995
    @deekshadubey6995 2 года назад +2

    Good explanation

  • @ashokk2983
    @ashokk2983 4 месяца назад

    for 153 number we got lastly num value 0 then sum is 1 ,how 1 and 0 equals,this number is armstrong,confused can u explain

  • @priyapriya4505
    @priyapriya4505 3 года назад +2

    Thanks brother

  • @thepr1ntgnome430
    @thepr1ntgnome430 3 года назад +2

    this will only work with 3 digits

    • @najmbe
      @najmbe Год назад

      Need to multiply the times the length of number eg: if 4 digit number then its sum+(remainder*remainder*remainder*remainder)

  • @monikaphalle9174
    @monikaphalle9174 3 года назад +1

    When number is 15 then how u calculated sum equal to 125 please explain

    • @InterviewPoint
      @InterviewPoint  3 года назад +1

      get the last digit of 15, it will be 5. Now the cube of 5 is 125. Hope now its clear for you

    • @monikaphalle9174
      @monikaphalle9174 3 года назад +1

      @@InterviewPoint no but sum is 27 so 27+125 should be 152

    • @InterviewPoint
      @InterviewPoint  3 года назад +1

      @@monikaphalle9174 Okay, actually you forget about 1 in 153 there is 1 also present, so the cube of 1 is 1,....
      Now add the cube of each digit 27+125+1=153

    • @InterviewPoint
      @InterviewPoint  3 года назад +1

      @@monikaphalle9174 Please use the debugger and check the value at each point. Because logic is correct.