Can any one help me to add number in a singly linked list?
here is my code...
Code:
#include<stdio.h>
#include<stdlib.h>
struct node {
int number;
struct node *next;
}*head;
int Insert(int num)
{
struct node *temp;
temp=(struct node*)malloc(sizeof(struct node));
temp=head;
while(temp->next!=NULL){
temp=temp->next;
}
temp->next=(struct node*)malloc(sizeof(struct node));
temp->number=num;
temp->next=NULL;
head=temp;
//struct node *temp;
//temp=(struct node*)malloc(sizeof(struct node));
//temp->number=num;
// temp->next=head;
// head=temp;//
}
void display(){
struct node *temp;
temp=head;
while(temp!=NULL){
printf("%d ",temp->number);
temp=temp->next;
}
}
int main()
{
int n,num,i=0;
printf("How many number do you want to input??\n");
scanf("%d",&n);
for(i=0;i<n;i++){
printf("Enter Your number- %d - ",i+1);
scanf("%d",&num);
Insert(num);
}
printf("Your number are--");
display();
}