0
1.1kviews
Write a program that creates two integer arrays of size 8 and 7. Initialize the arrays with random values.

Sort the arrays in ascending order with the help of a user defined function namely ‘sort Array’. Merge these arrays with the help of another user defined function named ‘merge Arrays’ which returns a new array. Program should display the arrays before and after sorting ,also the merged array.

Subject : Structured Programming Approach

Title : Arrays, String, Structures and Union

Difficulty : Medium

1 Answer
0
50views

Program:

#include<conio.h>

#include<stdio.h>

void main()

{

    int a[25],b[25],sum[50],i,j,k=1,n,m,s,temp;

    clrscr();

    printf("Enter the number of element in first array :");

    scanf("%d",&n);

    printf("\nEnter the element of array :\n");

    for(i=1;i<=n;i++)

        scanf("%d",&a[i]);

    printf("\nEnter the number of element in second array :");

    scanf("%d",&m);

    printf("\nEnter the element of array :\n");

    for(i=1;i<=m;i++)

        scanf("%d",&b[i]);

    s=m+n;

    for(i=1;i<=s;i++)

    {

        if(i<=n)

        {

            sum[i]=a[i];

        }

        else

        {

            sum[i]=b[k];

            k=k+1;

        }

    }

    printf("\n Array before sorting is\n");

    for(i=1;i<=s;i++)

        printf("%d\t",sum[i]);

        for(i=1;i<=s;i++)

        {

            for(j=1;j<=s;j++)

            {

                if(sum[i]<=sum[j])

                {

                    temp=sum[i];

                    sum[i]=sum[j];

                    sum[j]=temp;

                }

            }

        }

    printf("\nElement of array after sorting is :\n");

    for(i=1;i<=s;i++)

        printf("%d\t",sum[i]);

    getch();

}

Output:

Enter the number of elements in first array: 8

Enter the element of array:

1 4 7 8 9 22 66 11

Enter the number of elements in second array: 7

33 55 88 14 16 18 79

Array before sorting is

1 4 7 8 9 22 66 11 33 55 88 14 16 18 79

Array after sorting is 

1 4 7 8 9 11 14 16 18 22 33 55 66 79 88
Please log in to add an answer.