/
***************************************************************************
***
Online C Compiler.
Code, Compile, Run and Debug C program online.
Write your code in this editor and press "Run" button to compile and execute it.
***************************************************************************
****/
#include<stdio.h>
#include<stdlib.h>
struct node{
int data;
struct node *next;
};
int main()
{
int i, n, num;
struct node *start, *nnode, *temp;
printf(" Input the number of nodes : ");
scanf("%d", &n);
start=(struct node *)malloc(sizeof(struct node));
printf(" Input data for node 1 : ");
scanf("%d", &num);
start->data = num;
start->next = NULL;
temp = start;
for(i=2;i<=n;i++)
{
nnode = (struct node *)malloc(sizeof(struct node));
printf(" Input data for node %d : ", i);
scanf(" %d", &num);
nnode->data = num;
nnode->next = NULL;
temp->next = nnode;
temp = temp->next;
}
while (start!=NULL)
{
printf(" Data = %d\n", start->data);
start = start->next;
}
/*struct node *START=NULL, *SECOND, *THIRD;
START=(struct node *)malloc(sizeof(struct node));
//SECOND=(struct node *)malloc(sizeof(struct node));
//THIRD=(struct node *)malloc(sizeof(struct node));
//START=malloc(sizeof(struct node));
START->data=50;
START->next=NULL;
SECOND=(struct node *)malloc(sizeof(struct node));
SECOND->data=60;
SECOND->next=NULL;
START->next=SECOND;
THIRD=(struct node *)malloc(sizeof(struct node));
THIRD->data=70;
THIRD->next=NULL;
SECOND->next=THIRD;
printf("\n%d\n%d\n%d",START->data, SECOND->data, THIRD->data);*/
return 0;
}