Googolplex Program
-
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; }
-
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; }
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
-
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; }
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
-
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
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
-
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; }
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] -
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]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
-
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
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 -
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
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
withnew
,free
withdelete
, using classes, namespaces, etc...
TOXCCT >>> GEII power
[toxcct][VisualCalc] -
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
withnew
,free
withdelete
, using classes, namespaces, etc...
TOXCCT >>> GEII power
[toxcct][VisualCalc]Thank you for your time. Eric
-
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
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