Reverse An Integer Number | C Programming Example

Поділитися
Вставка
  • Опубліковано 12 гру 2024

КОМЕНТАРІ • 32

  • @tweetybird155
    @tweetybird155 2 роки тому +7

    SUCH A LIFE SAVER THANK YOU FOR THIS!

  • @tahmidanzum151
    @tahmidanzum151 2 роки тому +4

    Well explanation, thank you

  • @bkarthik455
    @bkarthik455 9 місяців тому +2

    What happens when last digit takens as zero
    Ex:- if i want to reverse a num 7890
    What will the output
    I run the program of 7890
    I got the output as 987 but it doesn't show 0 at starting in reverse of a number. Could pls explain this.

  • @cobblie8789
    @cobblie8789 Рік тому

    Is there any way to do this without using a loop?

  • @kartikthakur6931
    @kartikthakur6931 8 місяців тому

    what will this program do at 1111111113, as it's reversal will be out of int -datatype value limits.

    • @AcunPearce
      @AcunPearce 5 місяців тому

      you can use long data type

  • @agm3194
    @agm3194 Рік тому

    Which code editor is it?

  • @akshaypundir8333
    @akshaypundir8333 Рік тому

    how to prevent signed integer overflow

    • @PortfolioCourses
      @PortfolioCourses  Рік тому

      You might find this stackoverflow answer helpful: stackoverflow.com/a/62943541. :-)

  • @mccauleybacalla2228
    @mccauleybacalla2228 3 місяці тому

    thanks!

  • @ingénieureinformatique-h5y
    @ingénieureinformatique-h5y Місяць тому

    Thanks 😅

  • @mxhell3867
    @mxhell3867 Рік тому

    How to reverse an integer with leading zeroes or only zeroes?
    Like :
    Input: 009921
    Ouput: 129900
    Input: 000
    Output: 000
    Thanks in advance!

    • @PortfolioCourses
      @PortfolioCourses  Рік тому

      How is the integer stored in this case? As a string? If so we could just reverse the string. If it's not stored as a string, then how do we know how many leading zeros there are?

    • @lumiplex404
      @lumiplex404 10 місяців тому

      the leading zeros don't have a value so thee programme wouldn't count them or know how many zeros were used there.

    • @mxhell3867
      @mxhell3867 10 місяців тому

      @@PortfolioCourses sorry for late reply, yeah we have to work with strings otherwise we won't even know if user put any zeroes..

    • @PortfolioCourses
      @PortfolioCourses  10 місяців тому

      @@mxhell3867 Ah OK, well if it's a string, and it's a positive integer for sure, then you could technically just reverse the string itself: ua-cam.com/video/PtSHcou0WIs/v-deo.html. 🙂 If it could be a negative number, then you could check if the first char in the string is '-', and if it is, reverse the portion of the string after the '-' only.

  • @lumiplex404
    @lumiplex404 10 місяців тому

    Try reversing a negative number with this programme :)

    • @PortfolioCourses
      @PortfolioCourses  10 місяців тому

      It works with negative numbers. :-)

    • @lumiplex404
      @lumiplex404 10 місяців тому

      @@PortfolioCourses Try it, it will throw the code into an infinite loop because negative numbers don't return 0 after dividing it again and again. Only 1 minus(-) can change the whole game. Maybe thats why my maths teacher told me to be careful if the problem contains minus 😆

    • @PortfolioCourses
      @PortfolioCourses  10 місяців тому

      @@lumiplex404 No that's incorrect, it works. Did you try it? I tried using negative numbers before I created the video, and then again after your comment, and it works. I've now tried it for a 3rd time on 3 different compilers, and it still works. 🙂

    • @lumiplex404
      @lumiplex404 10 місяців тому

      @@PortfolioCourses Even in the leetcode solutions, they avoided negative numbers in the following way
      if x < 0:
      return False

    • @PortfolioCourses
      @PortfolioCourses  10 місяців тому

      @@lumiplex404 I don't understand what leetcode has to do with this solution being correct or incorrect with negative integers. Did you try it yet? The code is available here: github.com/portfoliocourses/c-example-code/blob/main/reverse_integer.c