here you find the best simplest implement of programs

code_world

love programing and watch my all easy implement of program hope you like it

Friday, 12 May 2017

implement of factorial of a number



                      factorial of a number 


#include<stdio.h>
#include<conio.h>
void main()
{
 int a[5],i,n,b=1,l;
 clrscr();
 for(i=0;i<5;i++)
 {
  scanf("%d",&a[i]);
 }
 for(i=0;i<5;i++)
 {
  b=a[i];
  l=a[i]-1;
  if(b<=7)
  {
   while(l>=1)
   {
   b=b*l;
   l--;
   }
  printf("%d ",b);
 }
 }
 getch();
}
Share:

Monday, 8 May 2017

Implementation of linked list using C


                         Implementation of linked list 



#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void beg_insertion();
void end_insertion();
void beg_deletion();
void end_deletion();
void display();
struct node
{
int info;
struct node *next;
}typedef node1;
node1 *first=NULL;
void main()
{
 int ch;
 clrscr();
 cq:
 printf("\npress 1 for beg insert\n");
 printf("press 2 for end insert\n");
 printf("press 3 for beg delete\n");
 printf("press 4 for end delete\n");
 printf("\n press 6 for display\n");
 printf("press 5 for exit\n");
 printf("enter your choice=");
 scanf("%d",&ch);
 switch(ch)
 {
  case 1:beg_insertion();
goto cq;
  case 2:end_insertion();
goto cq;
  case 3:beg_deletion();
goto cq;
  case 4:end_deletion();
goto cq;
  case 5:exit(0);
goto cq;
  case 6:display();
goto cq;
  default:printf("wrong input");
goto cq;
  }
  }
 void beg_insertion()
 { int item1;
node1 *ptr=(node1*)malloc(sizeof(node1));

printf("enter link list\n");
scanf("%d",&item1);
ptr->info=item1;
if(first==NULL)
{first=ptr;
ptr->next=NULL;
}
else
{ptr->next=first;
 first=ptr;
}
getch();
}

void end_insertion()
{
int item2;
node1 *temp;
node1 *ptr=(node1*)malloc(sizeof(node1));
printf("enter link list\n");
scanf("%d",&item2);
ptr->info=item2;

if(first==NULL)
{
ptr->next=NULL;
first=ptr;
}
else
{
temp=first;
while(temp->next!=NULL)
{
temp=temp->next;
}
ptr->next=NULL;
temp->next=ptr;
}
getch();
}
void beg_deletion()
{
if(first==NULL)
printf("linked list is empty");
else
{
node1 *ptr;
ptr=first;
first=first->next;
printf("deleted element is %d",ptr->info);
free(ptr);
}getch();
}

void end_deletion()
{
node1 *loc,*ptr;
if(first->next==NULL)
{
ptr=first;
free(ptr);
}
else if(first->next==NULL)
{
ptr=first;
first=NULL;
free(ptr);
}
else
{
loc=first;
ptr=first->next;
while(ptr->next!=NULL)
{
ptr=ptr->next;
loc=loc->next;
}
loc->next=NULL;
printf("deleted element is %d",ptr->info);
free(ptr);
}
}
void display()
{node1 *ptr;
ptr=first;
if(first==NULL)
{printf("empty"); return;}
else
{
while(ptr!=NULL)
{
printf("%d",ptr->info);
ptr=ptr->next;
}
}
getch();
}
Share:

Saturday, 6 May 2017

implement of merge sort in simplest way


                                   Merge sort



#include <stdio.h>
#include <conio.h>

void main( )
{
    int a[5] = { 13, 5, 6, 3, 56 } ;
    int b[5] = { 24, 1, 12, 9, 37 } ;
    int c[10] ;
    int i, j, k, temp ;

    clrscr() ;

    printf ( "Merge sort.\n" ) ;

    printf ( "\nFirst array:\n" ) ;
    for ( i = 0 ; i <= 4 ; i++ )
printf ( "%d\t", a[i] ) ;

    printf ( "\n\nSecond array:\n" ) ;
    for ( i = 0 ; i <= 4 ; i++ )
printf ( "%d\t", b[i] ) ;

    for ( i = 0 ; i <= 3 ; i++ )
    {
for ( j = i + 1 ; j <= 4 ; j++ )
{
   if ( a[i] > a[j] )
   {
temp = a[i] ;
a[i] = a[j] ;
a[j] = temp ;
   }
   if ( b[i] > b[j] )
   {
temp = b[i] ;
b[i] = b[j] ;
b[j] = temp ;
   }
}
    }

    for ( i = j = k = 0 ; i <= 9 ; )
    {
if ( a[j] <=  b[k] )
   c[i++] = a[j++] ;
else
   c[i++] = b[k++] ;

if ( j == 5 || k == 5 )
   break ;
    }

    for ( ; j <= 4 ; )
c[i++] = a[j++] ;

    for ( ; k <= 4 ; )
c[i++] = b[k++] ;

    printf ( "\n\nArray after sorting:\n") ;
    for ( i = 0 ; i <= 9 ; i++ )
printf ( "%d\t", c[i] ) ;

    getch( ) ;
}
Share:

Friday, 5 May 2017

implement of stack using c



                     implement of stack using c  


#include<stdio.h>
#include<conio.h>
#define MAX 3
int st[MAX],top=-1;
void push(int st[]);
void pop(int st[]);
void display(int st[]);
void main()
{
int option;
clrscr();
p:
printf("main menu");
printf("\n1: insert");
printf("\n2: delete");
printf("\n3: display");
printf("\n4: exit");
printf("\nenter the value");
scanf("%d",&option);
switch(option)
{
 case 1: push(st);
goto p;
 case 2: pop(st);
goto p;
 case 3: display(st);
goto p;
 defult:exit(0);
 printf("%d",option);
 }
getch();
}
void push(int st[])
{
 int n;
 printf("enter the element ");
 scanf("%d",&n);
 if(top== MAX -1)
  {
    printf("stack overflow");
  }
  else
  {
    top++;
    st[top] = n;
    printf("%d",n);

  }
 }
 void pop(int st[])
  {
   int n;
   printf("enter the element");
   scanf("%d",&n);
   if(top==-1)
   {
     printf("stack is underflow");
   }
   else
  {
    n =st[top];
    top--;
  printf("%d",n);
  }
 }
 void display(int st[])
 {
  int i;
  if(top==-1)
  {
  printf("no element in  the stack");
  }
  else
  {
   for(i=top;i>=0;i--)
   printf("%d",st[i]);
   printf("\n");
   }
  }


Share:

Thursday, 4 May 2017

program of linear search



                        linear search



#include<stdio.h>
#include<conio.h>
#define size 5
void main()
{
 int a[size],i,pos=-1,val;
 clrscr();
 printf("enter the element");
 for(i=0;i<size;i++)
 {
  scanf("%d",&a[i]);
 }
 printf("enter the value to be search");
 scanf("%d",&val);
 pos=0;
 for(i=0;i<=size;i++)
 {
   if(a[i]==val)
   {
   pos=val;
  printf("elemnt was found in %d\n",pos);
 }
 else
 {
  printf("element not found\n");
 }
}
 getch();
}


Share:

Wednesday, 3 May 2017

insertion sort using c


                 INSERTION SORT USING C


#include<stdio.h>
#include<conio.h>
#define size 5
void main()
{
 int i,j,temp,a[size];
 clrscr();
 printf("enter the element");
 for(i=0;i<size;i++)
 scanf("%d",&a[i]);
for(i=0;i<size;i++)
{
 j=i;
 while(j>0 && (a[j] < a[j-1]))
 {
  temp = a[j];
  a[j] = a[j-1];
  a[j-1] = temp;
   j--;
  }
 }
  for(i=0;i<size;i++)
  printf("\nsorted element%d",a[i]);
  getch();
 }

Share:

Tuesday, 2 May 2017

Find the length of a string

                length of a string  


#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
 char str[10],length,i=0;
 clrscr();
 printf("\nenter the string");
 gets(str);
 while(str[i]!='\0')
  i++;
  length = i;
  printf("\n the lenght of string %d",length);
  getch();
 }
Share: