> Online tutorial

print without using semicolon

    #include "conio.h"
    #include "stdio.h"
    void main()
    {
    if(printf("hello")&&getch())
    }

multiplication tables using c

0*10 Multiplication Table C code.



Sample Code

    #include<stdio.h>
    #include<conio.h>
    main()
    {
    int row,column;
    clrscr();
    puts("tttMULTIPLICATION TABLE");
    puts("nttt********************");
    for(row=1;row<=10;row++)
    {
    printf("nn");
    for(column=1;column<=10;column++)
    printf("%6d", row*column);
    }
    getch();
    }

armstrong number in c

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

void main()
{
        long num1,num2=0,mcount=0, nums;
        char str1[35], strc;

        clrscr();
        printf("Enter a number : ");
        scanf("%ld",&num1);

         ltoa(num1,str1,10);
         while (mcount <= (strlen(str1)-1))
         {
          strc = str1[mcount];
          nums = atoi(&strc);
          num2 = num2+pow(nums,3);
          mcount = mcount+1;
         }

         if (num1 == num2)
         {
          printf("Amstrong Number : %ld",num2);
         }
         else
         {
          printf("Not a Amstrong Number.");
         }
   getch();
}
 

doubly linked list program in c

doubly linked list program in c

        This a sample program of double linked list! the advantage of double over single is that singly linked list has the node inserted only at one end. and the pointer corresponds to the next pointer. but in a doubly linked list, the node pointer points to the both previous and the next node. singly linked list has two nodes doubly linked list has three nodes A doubly linked list makes sense when you need to traverse the list in both directions. You aren't able to do that with a singly linked list.



Sample Code

    #include <stdio.h>
    #include <stdlib.h>
    
    struct dllist
{
     int number;
     struct dllist *next;
     struct dllist *prev;
    };
    
    struct dllist *head, *tail;
    
    void append_node(struct dllist *lnode);
    void insert_node(struct dllist *lnode, struct dllist *after);
    void remove_node(struct dllist *lnode);
    
    int main(void) {
     struct dllist *lnode;
     int i = 0;
    
     /* add some numbers to the double linked list */
     for(i = 0; i <= 5; i++) {
      lnode = (struct dllist *)malloc(sizeof(struct dllist));
      lnode->number = i;
      append_node(lnode);
     }
    
     /* print the dll list */
     for(lnode = head; lnode != NULL; lnode = lnode->next) {
      printf("%dn", lnode->number);
     }
    
     /* destroy the dll list */
     while(head != NULL)
      remove_node(head);
    
     return 0;
    }
    
    void append_node(struct dllist *lnode)
{
     if(head == NULL)
 {
      head = lnode;
      lnode->prev = NULL;
     }
else
{
      tail->next = lnode;
      lnode->prev = tail;
     }
    
     tail = lnode;
     lnode->next = NULL;
    }
    
    void insert_node(struct dllist *lnode, struct dllist *after)
{
     lnode->next = after->next;
     lnode->prev = after;
    
     if(after->next != NULL)
      after->next->prev = lnode;
     else
      tail = lnode;
    
     after->next = lnode;
    }
    
    void remove_node(struct dllist *lnode)
{
     if(lnode->prev == NULL)
      head = lnode->next;
     else
      lnode->prev->next = lnode->next;
    
     if(lnode->next == NULL)
      tail = lnode->prev;
     else
      lnode->next->prev = lnode->prev;
    }


    

single linked list program in c


Single linked list inplementation using different functions

1. Insert a number at the beginning
2. Insert a number at last
3. Insert a number at a particular location in list
4. Print the elements in the list
5. Print the total number of elements in the list
6. Delete a node in the linked list
7. Reverse a linked list
8. Get out of linked list



Sample Code

    /* PROGRAM IMPLEMENTATION OF SINGLE LINKED LIST */
    
    #include"stdio.h"
    //#define NULL 0
    /* STRUCTURE CONTANING A DATA PART AND A LINK PART */
    
    struct node
    {
    int data;
    struct node *next;
    }*p;
    
    /* P IS A GLOBAL POINTER CONTAINS THE ADRESS OF THE FIRST NODE IN
    LIST
    */
    
    /*THIS FUNCTION DELETES A NODE */
    
    delnode(int num)
    {
    struct node *temp, *m;
    temp=p;
    while(temp!=NULL)
    {
    if(temp->data==num)
    {
    if(temp==p)
    {
    p=temp->next;
    free(temp);
    return;
    }
    else
    {
    m->next=temp->next;
    free(temp);
    return;
    }
    }else
    {
    m=temp;
    temp= temp->next;
    }
    
    }
    printf("    ELEMENT %d NOT FOUND    ", num);
    }/*THIS FUNCTION ADDS A NODE AT THE LAST OF LINKED LIST */
    
    append( int num )
    {
    struct node *temp,*r;
    /* CREATING A NODE AND ASSIGNING A VALUE TO IT */
    
    temp= (struct node *)malloc(sizeof(struct node));
    temp->data=num;
    r=(struct node *)p;
    
    if (p == NULL) /* IF LIST IS EMPTY CREATE FIRST NODE */
    {
    p=temp;
    p->next =NULL;
    }
    else
    { /* GO TO LAST AND ADD*/
    
    while( r->next != NULL)
    r=r->next;
    r->next =temp;
    r=temp;
    r->next=NULL;
    }
    }/* ADD A NEW NODE AT BEGINNING */
    
    addbeg( int num )
    {
    /* CREATING A NODE AND INSERTING VALUE TO IT */
    
    struct node *temp;
    temp=(struct node *)malloc(sizeof(struct node));
    temp->data=num;
    
    /* IF LIST IS NULL ADD AT BEGINNING */
    if ( p== NULL)
    {
    p=temp;
    p->next=NULL;
    }
    
    else
    {
    temp->next=p;
    p=temp;
    }
    }
    
    /* ADD A NEW NODE AFTER A SPECIFIED NO OF NODES */
    
    addafter(int num, int loc)
    {
    int i;
    struct node *temp,*t,*r;
    r=p;         /* here r stores the first location */
    if(loc > count()+1 || loc <= 0)
    {
    printf("    insertion is not possible :    ");
    return;
    }
    if (loc == 1)
/* if list is null then add at beginning */
    {
    addbeg(num);
    return;
    }
    else
    {
    for(i=1;i<loc;i++)
    {
    t=r;
/* t will be holding previous value */
    r=r->next;
    }
    temp=(struct node *)malloc(sizeof(struct node));
    temp->data=num;
    t->next=temp;
    t=temp;
    t->next=r;
    return;
    }
    }/* THIS FUNCTION DISPLAYS THE CONTENTS OF THE LINKED LIST */
    
    display(struct node *r)
    {
    r=p;
    if(r==NULL)
    {
    printf("NO ELEMENT IN THE LIST :");
    return;
    }
    /* traverse the entire linked list */
    while(r!=NULL)
    {
    printf(" -> %d ",r->data);
    r=r->next;
    }
    printf("");
    }
    //THIS FUNCTION COUNTS THE NUMBER OF ELEMENTS IN THE LIST
    count()
    {
    struct node *n;
    int c=0;
    n=p;
    while(n!=NULL)
    {
    n=n->next;
    c++;
    }
    return(c);
    }
    //THIS FUNCTION REVERSES A LINKED LIST
    reverse(struct node *q)
    {
    struct node *m, *n,*l,*s;
    m=q;
    n=NULL;
    while(m!=NULL)
    {
    s=n;
    n=m;
    m=m->next;
    n->next=s;
    }
    p=n;
    }
    
    
    /* THIS IS THE MAIN PROGRAM */
    
    main()
    {
    int i;
    p=NULL;
    while(1) /* this is an indefinite loop */
    {
    printf("    1.INSERT A NUMBER AT BEGINNING;<BR>);
    printf("    2.INSERT A NUMBER AT LAST:<BR>);
    printf("    3.INSERT A NUMBER AT A PARTICULAR LOCATION INlIST:<BR>);
    printf("    4.PRINT THE ELEMENTS IN THE LIST :<BR>);
    printf("    5.PRINT THE NUMBER OF ELEMENTS IN THE LIST <BR>);
    printf("    6.DELETE A NODE IN THE LINKED LIST:<BR>);
    printf("    7.REVERSE A LINKED LIST :<BR>);
    printf("    8.GET OUT OF LINKED LIST (BYEE BYEE):<BR>);
    printf("    PLEASE, ENTER THE NUMBER:");
    
    scanf("%d",&i);
/* ENTER A VALUE FOR SWITCH */
    
    switch(i)
    {
    case 1:
    {
    int num;
    printf("
    PLEASE ENTER THE NUMBER :-");
    scanf("%d",&num);
    addbeg(num);
    break;
    }
    case 2:
    {
    int num;
    printf("
    PLEASE ENTER THE NUMBER :-");
    scanf("%d",&num);
    append(num);
    break;
    }
    
    case 3:
    {
    int num, loc,k;
    printf("
    PLEASE ENTER THE NUMBER :-");
    scanf("%d",&num);
    printf("
    PLEASE ENTER THE LOCATION NUMBER :-");
    scanf("%d",&loc);
    addafter(num,loc);
    break;
    }
case 4:
    {
    struct node *n;
    printf("
    
    THE ELEMENTS IN THE LIST ARE : <BR>);
    display(n);
    break;
    }
    
    case 5:
    {
    struct node *n;
    display(n);
    printf(" TOTAL NO OF ELEMENTS IN THE LSIT ARE %d",count());
    break;
    }
case 6:
    {
    int num;
    printf("
    PLEASE ENTER A NUMBER FROM THE LIST :");
    scanf("%d",&num);
    delnode(num);
    break;
    }
    case 7:
    {
    reverse(p);
    display(p);
    break;
    }
    case 8:
    {
    exit();
    }
    }/* end if switch */
    }/* end of while */
    }/* end of main */