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
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Googolplex Program

Googolplex Program

Scheduled Pinned Locked Moved C / C++ / MFC
c++performancehelpquestion
10 Posts 4 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.
  • E Offline
    E Offline
    ericelysia
    wrote on last edited by
    #1

    Hello, I found this program online. I think it might be written in C. Can someone convert this to Visual C++ for me? I would like to show my wife that she cannot visualize what a googolplex is. Thanks, Eric #include #include int main (int argc, char *argv[]) { int *vals, *ptr, max; if (argc == 2) max = atoi (argv[1]); else max = 100; printf ("1"); if ((vals = malloc ((max + 1) * sizeof (int))) == NULL) { fprintf (stderr, "Error allocating memory.\n"); return 1; } memset (vals, '\0', (max + 1) * sizeof (int)); while (!vals[max]) { *(ptr = vals) += 1; while (*ptr == 10) { *ptr++ = 0; *ptr += 1; } printf ("0"); } printf ("\n"); free (vals); return 0; }

    M D T 3 Replies Last reply
    0
    • E ericelysia

      Hello, I found this program online. I think it might be written in C. Can someone convert this to Visual C++ for me? I would like to show my wife that she cannot visualize what a googolplex is. Thanks, Eric #include #include int main (int argc, char *argv[]) { int *vals, *ptr, max; if (argc == 2) max = atoi (argv[1]); else max = 100; printf ("1"); if ((vals = malloc ((max + 1) * sizeof (int))) == NULL) { fprintf (stderr, "Error allocating memory.\n"); return 1; } memset (vals, '\0', (max + 1) * sizeof (int)); while (!vals[max]) { *(ptr = vals) += 1; while (*ptr == 10) { *ptr++ = 0; *ptr += 1; } printf ("0"); } printf ("\n"); free (vals); return 0; }

      M Offline
      M Offline
      Maximilien
      wrote on last edited by
      #2

      AFAIK, it's impossible to represent a googolplex, it should be bigger than the largest number you can think of ... much bigger than 100 digits in a number.


      Maximilien Lincourt Your Head A Splode - Strong Bad

      1 Reply Last reply
      0
      • E ericelysia

        Hello, I found this program online. I think it might be written in C. Can someone convert this to Visual C++ for me? I would like to show my wife that she cannot visualize what a googolplex is. Thanks, Eric #include #include int main (int argc, char *argv[]) { int *vals, *ptr, max; if (argc == 2) max = atoi (argv[1]); else max = 100; printf ("1"); if ((vals = malloc ((max + 1) * sizeof (int))) == NULL) { fprintf (stderr, "Error allocating memory.\n"); return 1; } memset (vals, '\0', (max + 1) * sizeof (int)); while (!vals[max]) { *(ptr = vals) += 1; while (*ptr == 10) { *ptr++ = 0; *ptr += 1; } printf ("0"); } printf ("\n"); free (vals); return 0; }

        D Offline
        D Offline
        David Crow
        wrote on last edited by
        #3

        ericelysia wrote:

        Can someone convert this to Visual C++ for me?

        Why? What significance would objects, encapsulation, inheritance, abstraction, or polymorphism have on this? Why not just write 1010100 on a piece of paper and show that to her?


        "Take only what you need and leave the land as you found it." - Native American Proverb

        E 1 Reply Last reply
        0
        • D David Crow

          ericelysia wrote:

          Can someone convert this to Visual C++ for me?

          Why? What significance would objects, encapsulation, inheritance, abstraction, or polymorphism have on this? Why not just write 1010100 on a piece of paper and show that to her?


          "Take only what you need and leave the land as you found it." - Native American Proverb

          E Offline
          E Offline
          ericelysia
          wrote on last edited by
          #4

          I just want her to see all of the zeros going and going and going. Is that what that C code is doing (100 ^ 10 ^ 100) ? If so, why does it look more complex? Thanks, Eric

          T D 2 Replies Last reply
          0
          • E ericelysia

            Hello, I found this program online. I think it might be written in C. Can someone convert this to Visual C++ for me? I would like to show my wife that she cannot visualize what a googolplex is. Thanks, Eric #include #include int main (int argc, char *argv[]) { int *vals, *ptr, max; if (argc == 2) max = atoi (argv[1]); else max = 100; printf ("1"); if ((vals = malloc ((max + 1) * sizeof (int))) == NULL) { fprintf (stderr, "Error allocating memory.\n"); return 1; } memset (vals, '\0', (max + 1) * sizeof (int)); while (!vals[max]) { *(ptr = vals) += 1; while (*ptr == 10) { *ptr++ = 0; *ptr += 1; } printf ("0"); } printf ("\n"); free (vals); return 0; }

            T Offline
            T Offline
            toxcct
            wrote on last edited by
            #5

            some already answered you, but my question is much based on the code. why do you want to convert this sample into "Visual C++" code ? if it is C, it will compile. just copy it into a .c file instead of a .cpp...


            TOXCCT >>> GEII power
            [toxcct][VisualCalc]

            E 1 Reply Last reply
            0
            • T toxcct

              some already answered you, but my question is much based on the code. why do you want to convert this sample into "Visual C++" code ? if it is C, it will compile. just copy it into a .c file instead of a .cpp...


              TOXCCT >>> GEII power
              [toxcct][VisualCalc]

              E Offline
              E Offline
              ericelysia
              wrote on last edited by
              #6

              OK, thank you. I did not know that. That's what I will do. I would also like to be able to understand the code. Is the C version of this program much different from the C++ version? Eric

              T 1 Reply Last reply
              0
              • E ericelysia

                I just want her to see all of the zeros going and going and going. Is that what that C code is doing (100 ^ 10 ^ 100) ? If so, why does it look more complex? Thanks, Eric

                T Offline
                T Offline
                toxcct
                wrote on last edited by
                #7

                ericelysia wrote:

                I just want her to see all of the zeros going and going and going.

                printf(" 100\n");
                printf(" 10\n");
                printf("100 = 1");
                int i = 0;
                int j = 0;
                for (i = 0; i < 100; i++) {
                for (j = 0; j < 100; j++) {
                printf("0");
                }
                }

                this will print the following :

                 100
                

                10
                100 = 1000000000000...


                TOXCCT >>> GEII power
                [toxcct][VisualCalc] -- modified at 12:39 Tuesday 1st November, 2005

                1 Reply Last reply
                0
                • E ericelysia

                  OK, thank you. I did not know that. That's what I will do. I would also like to be able to understand the code. Is the C version of this program much different from the C++ version? Eric

                  T Offline
                  T Offline
                  toxcct
                  wrote on last edited by
                  #8

                  ericelysia wrote:

                  Is the C version of this program much different from the C++ version?

                  C++ when created wanted to conserve with few exceptions the C language as a subset. so, C code will mostly compile on a C++ compiler... now, if you'd really like to change it into pure Standard complient C++, you would have some little changes such as malloc with new, free with delete, using classes, namespaces, etc...


                  TOXCCT >>> GEII power
                  [toxcct][VisualCalc]

                  E 1 Reply Last reply
                  0
                  • T toxcct

                    ericelysia wrote:

                    Is the C version of this program much different from the C++ version?

                    C++ when created wanted to conserve with few exceptions the C language as a subset. so, C code will mostly compile on a C++ compiler... now, if you'd really like to change it into pure Standard complient C++, you would have some little changes such as malloc with new, free with delete, using classes, namespaces, etc...


                    TOXCCT >>> GEII power
                    [toxcct][VisualCalc]

                    E Offline
                    E Offline
                    ericelysia
                    wrote on last edited by
                    #9

                    Thank you for your time. Eric

                    1 Reply Last reply
                    0
                    • E ericelysia

                      I just want her to see all of the zeros going and going and going. Is that what that C code is doing (100 ^ 10 ^ 100) ? If so, why does it look more complex? Thanks, Eric

                      D Offline
                      D Offline
                      David Crow
                      wrote on last edited by
                      #10

                      ericelysia wrote:

                      Is that what that C code is doing (100 ^ 10 ^ 100) ?

                      I did not look at the code that close, but a googleplex is 10 raised to the power of a google, or 10 ^ (10 ^ 100).


                      "Take only what you need and leave the land as you found it." - Native American Proverb

                      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