Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. breaking up an int in c programming

breaking up an int in c programming

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestion
7 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    neodeaths
    wrote on last edited by
    #1

    i am using c programming hi i need to break up an int value to parts any one know how to do that? example 112233 i need to stor them as 11 22 33 wats the function for it?

    C M K 3 Replies Last reply
    0
    • N neodeaths

      i am using c programming hi i need to break up an int value to parts any one know how to do that? example 112233 i need to stor them as 11 22 33 wats the function for it?

      C Offline
      C Offline
      codeII
      wrote on last edited by
      #2

      int nValue = 112233;
      int n1 = nValue / 10000;
      nValue -= ( n1 * 10000 );
      int n2 = nValue / 100;
      nValue -= ( n2 * 100 );
      int n3 = nValue;

      1 Reply Last reply
      0
      • N neodeaths

        i am using c programming hi i need to break up an int value to parts any one know how to do that? example 112233 i need to stor them as 11 22 33 wats the function for it?

        M Offline
        M Offline
        Malli_S
        wrote on last edited by
        #3

        int i = 112233; while(i) { cout< -**Malli**...! :rose:****

        C 1 Reply Last reply
        0
        • M Malli_S

          int i = 112233; while(i) { cout< -**Malli**...! :rose:****

          C Offline
          C Offline
          chandu004
          wrote on last edited by
          #4

          cool, but here arent the numbers getting printed in reverse.

          C CPalliniC 2 Replies Last reply
          0
          • N neodeaths

            i am using c programming hi i need to break up an int value to parts any one know how to do that? example 112233 i need to stor them as 11 22 33 wats the function for it?

            K Offline
            K Offline
            KarstenK
            wrote on last edited by
            #5

            Easy: Format a string out of it and than split as you want. Fast: shifting look for ">>" operator. zzz:

            Greetings from Germany

            1 Reply Last reply
            0
            • C chandu004

              cool, but here arent the numbers getting printed in reverse.

              C Offline
              C Offline
              codeII
              wrote on last edited by
              #6

              int nValue = 112233;
              int nDiv = 1000000;

              while ( nDiv /= 100 ) //StepSize
              {
              cout<

              1 Reply Last reply
              0
              • C chandu004

                cool, but here arent the numbers getting printed in reverse.

                CPalliniC Offline
                CPalliniC Offline
                CPallini
                wrote on last edited by
                #7

                void breakint(int i)
                {
                if (i%100)
                {
                breakint(i/100);
                printf("%d \n", i%100);
                }
                else
                return;
                }

                :-D

                If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

                In testa che avete, signor di Ceprano?

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups