Our website is made possible by displaying online advertisements to our visitors.Please consider supporting us by disabling your ad blocker.
Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu
Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Translate it in your own Language

Print this Job Post

Print Friendly and PDF

Friday, May 23, 2014

C programming code to merge two sorted arrays

#include <stdio.h>
#include<conio.h> 
void merge(int [], int, int [], int, int []);
void main() 
{
  int a[100], b[100], m, n, c, sorted[200];
  clrscr(); 
  printf("Input number of elements in first array\n");
  scanf("%d", &m);
  printf("Input %d integers\n", m);
  for (c = 0; c < m; c++) 
  {
  scanf("%d", &a[c]);
  }
  printf("Input number of elements in second array\n");
  scanf("%d", &n);
  printf("Input %d integers\n", n);
  for (c = 0; c < n; c++) 
  {
   scanf("%d", &b[c]);
  }

  merge(a, m, b, n, sorted);
  printf("Sorted array:\n");
  for (c = 0; c < m + n; c++) 
  {
  printf("%d\n", sorted[c]);
  }
  getch();
}

void merge(int a[], int m, int b[], int n, int sorted[]) 
{
  int i, j, k;
  j = k = 0;
  for (i = 0; i < m + n;) 
  {
    if (j < m && k < n) 
    {
      if (a[j] < b[k]) 
      {
        sorted[i] = a[j];
        j++;
      }
     else 
     {
       sorted[i] = b[k];
       k++;
      }
     i++;
   }
   else if (j == m) 
   {
     for (; i < m + n;) 
     {
       sorted[i] = b[k];
        k++;
        i++;
      }
    }
    else 
    {
      for (; i < m + n;) 
      {
        sorted[i] = a[j];
         j++;
         i++;
       }
     }
   }
 }

Output of program:



Thursday, May 22, 2014

C programming code

#include <stdio.h>
#include<conio.h> 
void main()
{
   int array[100], position, c, n;
   clrscr();
   printf("Enter number of elements in array\n");
   scanf("%d", &n);
   printf("Enter %d elements\n", n);
   for ( c = 0 ; c < n ; c++ )
   scanf("%d", &array[c]);
   printf("Enter the location where you wish to delete element\n");
   scanf("%d", &position);
   if ( position >= n+1 )
   printf("Deletion not possible.\n");
   else
   {
      for ( c = position - 1 ; c < n - 1 ; c++ )
      array[c] = array[c+1];
      printf("Resultant array is\n");
      for( c = 0 ; c < n - 1 ; c++ )
      printf("%d\n", array[c]);
   }
   getch();
}

Output Of Program:


HCL Placement Paper-1               
HCL Placement Paper-2               

HCL Placement Paper-3               

HCL Placement Paper-4               

HCL Placement Paper-5               

HCL Placement Paper-6               

HCL Placement Paper-7               

HCL Placement Paper-8               

HCL Placement Paper-9               

HCL Placement Paper-10             

This code will insert an element into an array, For example consider an array a[10] having three elements in it initially and a[0] = 1, a[1] = 2 and a[2] = 3 and you want to insert a number 45 at location 1 i.e. a[0] = 45, so we have to move elements one step below so after insertion a[1] = 1 which was a[0] initially, and a[2] = 2 and a[3] = 3. Array insertion does not mean increasing its size i.e array will not be containing 11 elements.

C programming code

#include <stdio.h>
#include<conio.h> 
void main()
{
   int array[100], position, c, n, value;
   clrscr();
   printf("Enter number of elements in array\n");
   scanf("%d", &n);
   printf("Enter %d elements\n", n);
   for (c = 0; c < n; c++)
   scanf("%d", &array[c]);
   printf("Enter the location where you wish to insert an element\n");
   scanf("%d", &position);
   printf("Enter the value to insert\n");
   scanf("%d", &value);
   for (c = n - 1; c >= position - 1; c--)
   array[c+1] = array[c];
   array[position-1] = value;
   printf("Resultant array is\n");
   for (c = 0; c <= n; c++)
   printf("%d\n", array[c]);
   getch();
}

Output of program:


This program reverses the array elements. For example if a is an array of integers with three elements such that
a[0] = 1
a[1] = 2
a[2] = 3
Then on reversing the array will be
a[0] = 3
a[1] = 2
a[0] = 1

Given below is the c code to reverse an array.

C programming code

#include <stdio.h>
#include<conio.h> 
void main()
{
   int n, c, d, a[100], b[100];
   clrscr();
   printf("Enter the number of elements in array\n");
   scanf("%d", &n);
   printf("Enter the array elements\n");
   for (c = 0; c < n ; c++)
   scanf("%d", &a[c]);
   for (c = n - 1, d = 0; c >= 0; c--, d++)
   b[d] = a[c];
   for (c = 0; c < n; c++)
   a[c] = b[c];
   printf("Reverse array is\n");
   for (c = 0; c < n; c++)
   printf("%d\n", a[c]);
   getch();
}

Output of program:


Reverse array by swapping (without using additional memory)

#include <stdio.h>
#include<conio.h> 
void main() 
{
  int array[100], n, c, temp, end;
  clrscr(); 
  scanf("%d", &n);
  end = n - 1;
  for (c = 0; c < n; c++) 
 {
  scanf("%d", &array[c]);
  }
  for (c = 0; c < n/2; c++) 
 {
  temp = array[c];
  array[c]   = array[end];
  array[end] = temp;
  end--;
  }
  printf("Reversed array elements are:\n");
  for (c = 0; c < n; c++) {
  printf("%d\n", array[c]);
  }
  getch();
}


Wednesday, May 21, 2014

Also Checkout Tips and Tricks For cracking eLitmus Exam: Click Here

PAGE:12


If text is not visible in image then you can download and zoom it .....

To Download this image 
To Download in Pdf format  


        « Prev 123456789101112  Next »


Also Checkout Tips and Tricks For cracking eLitmus Exam: Click Here

PAGE:11


If text is not visible in image then you can download and zoom it .....

To Download this image  
To Download in Pdf format  




Also Checkout Tips and Tricks For cracking eLitmus Exam: Click Here

PAGE:10


If text is not visible in image then you can download and zoom it .....

To Download this image  
To Download in Pdf format  




Also Checkout Tips and Tricks For cracking eLitmus Exam: Click Here

PAGE:9


If text is not visible in image then you can download and zoom it .....

To Download this image  
To Download in Pdf format  




Also Checkout Tips and Tricks For cracking eLitmus Exam: Click Here

PAGE:8


If text is not visible in image then you can download and zoom it .....

To Download this image  
To Download in Pdf format  




Also Checkout Tips and Tricks For cracking eLitmus Exam: Click Here

PAGE:7

If text is not visible in image then you can download and zoom it .....

To Download this image  

To Download in Pdf format  


        « Prev 123456789101112  Next »



Also Checkout Tips and Tricks For cracking eLitmus Exam: Click Here

PAGE:6


If text is not visible in image then you can download and zoom it .....

To Download this image  
To Download in Pdf format  




Also Checkout Tips and Tricks For cracking eLitmus Exam: Click Here

PAGE:5

If text is not visible in image then you can download and zoom it .....

To Download this image  
To Download in Pdf format  




Also Checkout Tips and Tricks For cracking eLitmus Exam: Click Here

PAGE:4

If text is not visible in image then you can download and zoom it .....

To Download this image  
To Download in Pdf format  




Copyright @ CrackMNC 2014-2024
Divas Nikhra Theme by Crack MNC