Showing posts with label merge them and finally produce the ascending order sorting of the result. Show all posts
Showing posts with label merge them and finally produce the ascending order sorting of the result. Show all posts

Thursday 20 June 2013

Q. Write a program to get two different array values , merge them and finally produce the ascending order sorting of the result. (array Concept)-C programming

Array Concept: 
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
    int a[25],b[25],n,g=0,m,i,j,c,temp;
    clrscr();
    printf("Enter the number of a: ");
        scanf("%d",&n);
    printf("\nEnter the no of b: ");
        scanf("%d",&m);
    printf("\nEnter a values\n");
    for(i=1; i<=n ; i++)
        scanf("%d",&a[i]);
    printf("\nEnter b values\n");
    for(j=1; j<=m ; j++)
    {
        scanf("%d",&b[j]);
        a[i]=b[j];
        i++;
    }
    printf("\nMerged values:\n");
    c=n+m;
    for(i=1; i<=c; i++)
        printf("%d\t",a[i]);
    while(g < c)
    {
        for(i=1; i<=c; i++)
            if(a[i]>a[i+1])
            {
                temp=a[i];
                  a[i]=a[i+1];
                  a[i+1]=temp;
            }
            else
                a[i]=a[i];
    ++g;
    }
    printf("\nSorted Values:\n");
    for(i=1; i<=c; i++)
        printf("%d\t",a[i]);
getch();
}

Sample Output:



Note: 
 " Hi I am a Learner of C/C++. I have done this program with my own Knowledge. There may be easy way to solve this programs. So I am sorry if this program in your point of view is too long. "

Popular Posts