Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- #include<conio.h>
- int node_num=1;int sum=0;
- typedef struct Node node;
- struct Node{
- int x;
- node *next;
- }*head=NULL;
- void create()
- {
- int n;
- printf("Enter number of nodes:");
- scanf("%d",&n);
- node *temp,*current;
- temp=(node*)malloc(sizeof(node));
- printf("Enter data: ");
- scanf("%d",&temp->x);
- head=temp;
- temp->next=NULL;
- current=temp;
- for(int i=2;i<=n;i++)
- {
- temp=(node*)malloc(sizeof(node));
- scanf("%d",&temp->x);
- temp->next=NULL;
- current->next=temp;
- current=temp;
- node_num++;
- }
- }
- void display()
- {
- node *c=head;
- for(int i=1;i<=node_num;i++)
- {
- sum=sum+c->x;
- c=c->next;
- }
- }
- void l_insert()
- {
- node *temp,*store=head;
- temp=(node*)malloc(sizeof(node));
- printf("Insert new data:");
- scanf("%d",&temp->x);
- temp->next=NULL;
- for(int i=2;i<=node_num;i++)
- {
- store=store->next;
- }
- store->next=temp;
- node_num++;
- }
- int main()
- {
- create();
- l_insert();
- display();
- printf("Sum of total nodes: %d\n",sum);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement