C Programming Tutorial

 
 
 
 
#include<stdio.h>
#include<conio.h>
struct node
{
    int no;

    struct node *next;
};
    struct node *head;
    struct node  *p;
    struct node *temp;
    int ch1;

void main()
{


    int ctr,num;
    int arr[20],tempctr;
    char ch;

    clrscr();


    head = (struct node *)malloc(sizeof(struct node));

    printf(\"\\nEnter the no::\");
    flushall();
    scanf(\"%d\",&head->no);

    printf(\"\\nDo u want to create another node::\");
    flushall();
    scanf(\"%c\",&ch);

    p=head;
    while(ch==\'y\' || ch==\'Y\')
    {
        p->next=(struct node *)malloc(sizeof(struct node));
        p=p->next;

        printf(\"\\nEnter the no::\");
        flushall();
        scanf(\"%d\",&p->no);

        printf(\"\\nDo u want to create another node::\");
        flushall();
        scanf(\"%c\",&ch);
    }
    p->next=NULL;

    temp=head;
    ctr=0;
    while(temp!=NULL)
    {
        arr[ctr]=temp->no;
        ctr++;
        temp=temp->next;
    }
    tempctr=ctr;
    for(ctr=tempctr-1;ctr>=0;ctr--)
    {
        printf(\"\\n%d\",arr[ctr]);
    }
    getch();
}

 
 
Didn't find what you were looking for? Find more on Print reverse linked list