Posts

Showing posts from January, 2021

calloc() function

Implementation of calloc() function in C language:- #include<stdio.h> #include<malloc.h> int main(void){ int *ptr, n, i = 0; printf("enter the size of memory to allocate\n"); scanf("%d", &n); ptr = (int*)calloc(n,sizeof(int)); printf("\n%d\n", *ptr); while(i <= n-1) scanf("%d", ptr+i++); i = 0; while(i <= n-1) printf("%d\n", *(ptr+i++)); } here is a small program for implementation of calloc() function in C language

CIRCULAR QUEUE

To implement a circular queue data structure using an array, we first perform the following steps before we implement actual operations. Step 1 -  Include all the   header files   which are used in the program and define a constant   'MAX'   with specific value. Step 2 -  Declare all   user defined functions   used in circular queue implementation. Step 3 -  Create a one dimensional array with above defined SIZE ( int queue[MAX] ) Step 4 -  Define two integer variables   'front'   and ' rear ' and initialize both with   '-1' . ( int front = -1, rear = -1 ) Step 5 -  Implement main method by displaying menu of operations list and make suitable function calls to perform operation selected by the user on circular queue.  IMPLEMENTATION OF CIRCULAR QUEUE USING  C  LANGUAGE:- #include<stdio.h> #define MAX 5 void en_queue(); void de_queue(); void display(); int queue[MAX]; int rear = -1; int front = -1;...

bubble sort

 implementation of bubble sort using C language:- int main() {   int *array, i, j, swap, n;      printf("Enter number of elements\n");        scanf("%d",&n);               array = (int*)malloc(n*sizeof(int));              printf("Enter %d integers\n", n);              for (i = 0; i < n; i++)           scanf("%d",&array[i]);     for (i = 0 ; i < n-1; i++)   {     for (j = 0 ; j < n-i; j++)     {       if (array[j] > array[j+1])        {         swap       = array[j];         array[j]   = array[j+1];         array[j+1] = swap;       }     }   }     printf("Sorted list in ascending order:\n");  ...

binary search

IMPLEMENTATION  OF  BINARY SEARCH  IN  'C'  LANGUAGE:-  #include <stdio.h>           int main()     {        int i, first, last, middle, n, search;        int *ptr;              printf("Enter number of elements\n");        scanf("%d",&n);                ptr = (int*)malloc(n*sizeof(int));              printf("Enter %d integers\n", n);              for (i = 0; i < n; i++)           scanf("%d",&ptr[i]);              printf("Enter value to find\n");        scanf("%d", &search);              first = 0;        last = n - 1;        middle = (first+last)/2;...