C Program To Merge One Ascending And Another One Is Descending Array In Third Array Should be Descending Order

#include<stdio.h>
#include<conio.h>
int main()
{
    int a[50], b[50], c[100], limitA, limitB, i, j, limitC, temp;
    printf("How many elements you want to store in array A: ");
    scanf("%d", &limitA);
    printf("How many elements you want to store in array B: ");
    scanf("%d", &limitB);
    printf("Enter %d elements in array A:", limitA);
    for(i=0; i<limitA; i++)
        scanf("%d", &a[i]);
    printf("Enter %d elements in array B:", limitB);
    for(i=0; i<limitB; i++)
        scanf("%d", &b[i]);
    printf("\nElements of Array A are:\n");
    for(i=0; i<limitA; i++)
    {
        if(i==(limitA-1))
            printf("%d", a[i]);
        else
            printf("%d, ", a[i]);
    }
    printf("\n\nElements of Array B are:\n");
    for(i=0; i<limitB; i++)
    {
        if(i==(limitB-1))
            printf("%d", b[i]);
        else
            printf("%d, ", b[i]);
    }
    for(i=0; i<limitA; i++)
        c[i] = a[i];
    for(j=0; j<limitB; j++)
    {
        c[i] = b[j];
        i++;
    }
    limitC = i;
    for(j=0; j<(limitC-1); j++)
    {
        for(i=0; i<(limitC-1); i++)
        {
            if(c[i]<c[i+1])
            {
                temp = c[i];
                c[i] = c[i+1];
                c[i+1] = temp;
            }
        }
    }
    printf("\n\nElements of Array C are:\n");
    for(i=0; i<limitC; i++)
    {
        if(i==(limitC-1))
            printf("%d", c[i]);
        else
            printf("%d, ", c[i]);
    }
    getch();
    return 0;
}

Output:


		

Leave a Comment