-
-
Save chintanparikh/4019724 to your computer and use it in GitHub Desktop.
3.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include <stdlib.h> | |
| struct node { | |
| int data; | |
| struct *node next; | |
| }; | |
| void push(struct node** headRef, int data) | |
| { | |
| struct node* newNode; | |
| newNode = malloc(sizeof(struct node)); | |
| newNode->data = data; | |
| newNode->next = *headRef; | |
| *headRef = newNode; | |
| } | |
| struct node* primeFactors(int num) | |
| { | |
| struct node* head = NULL; | |
| if (num == 1) | |
| { | |
| return head; | |
| } | |
| int factor = 0; | |
| int i = 2; | |
| while (i <= num) | |
| { | |
| if (num % i) | |
| { | |
| factor = i; | |
| } | |
| } | |
| push(&head, factor); | |
| primeFactors(num / factor); | |
| return head; | |
| } | |
| int main(int argc, char const *argv[]) | |
| { | |
| struct node* head = primeFactor(600851475143); | |
| printf("%d/n", head->data); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [1] $ gcc 3.c -o 3 | |
| 3.c:6:9: error: expected ‘{’ before ‘*’ token | |
| 3.c: In function ‘push’: | |
| 3.c:14:9: error: ‘struct node’ has no member named ‘next’ | |
| 3.c: In function ‘main’: | |
| 3.c:42:22: warning: initialisation makes pointer from integer without a cast [enabled by default] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment