Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ///Home Work 13 @Nurnobi shanto
- #include<stdio.h>
- #include<stdlib.h>
- typedef struct Node{
- int data1;
- float data2;
- struct Node *ptr;
- }node;
- node *head = NULL;
- int main(){
- printf("Enter Data to store:\n");
- node *n1;
- n1 = (node*)malloc(sizeof(node));
- scanf("%d", &n1-> data1);
- scanf("%f", &n1-> data2);
- n1-> ptr = NULL;
- head = n1;
- node *n2;
- n2 = (node*)malloc(sizeof(node));
- scanf("%d", &n2->data1);
- scanf("%f", &n2->data2);
- n2-> ptr = NULL;
- n1-> ptr = n2;
- node *n3;
- n3 = (node*)malloc(sizeof(node));
- scanf("%d", &n3->data1);
- scanf("%f", &n3->data2);
- n3->ptr = NULL;
- n2-> ptr = n3;
- node *n4;
- n4 = (node*)malloc(sizeof(node));
- scanf("%d", &n4->data1);
- scanf("%f", &n4->data2);
- n4->ptr = NULL;
- n3-> ptr = n4;
- node *temp = head;
- int c = 0;
- while(temp != NULL){
- printf("Stored Data: %d\n", temp-> data1);
- printf("Stored Data: %.1f\n", temp-> data2);
- temp = temp-> ptr;
- c++;
- }
- printf("\nTotal node: %d\n\n", c);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement