| minwoo1989 |
괜찮지는 않지만 한번 짜봤는데요...
2^64승만 돼도 unsigned long long int 최대값보다 커지네요
#include <stdio.h>
#include <malloc.h>
struct list {
unsigned long long int data;
struct list *next;
};
typedef struct list List;
void insert(List*);
int main() {
List *head = (List*) malloc(sizeof(List));
head->data = NULL;
head->next = NULL;
// unsigned long long int의 최대값
unsigned long long int d = -1;
printf("max = %llu\n\n", d);
insert(head);
while (!head->next) {
printf("%llu", head->data);
tmp = head;
head = head->next;
free(tmp);
}
free(head);
return 0;
}
void insert(List *l) {
List *prev = l;
int i;
l->data = 2;
l->next = NULL;
for (i = 0; i < 127; i++) {printf("2^%d\n", i + 2);
List *d = (List*) malloc(sizeof(List));
d->data = prev->data * 2;
d->next = NULL;
printf("-----%llu\n", d->data);
prev->next = d;
prev = prev->next;
}
} |
2012/05/16 |
|