Extra 5% OFF Use Code: OL05
Free Shipping over ₹999

Compare middel element of array

#include<stdio.h>
void main()
{
    int i,insert[10],md,n,dif;
    printf("How many element (you can choose only odd number):");
    scanf("%d",&n);
    if(n%2==0)
    {
        printf("Number is invalid:");
    }
    if(n%2!=0)
    {
        // find middle element of an array
        md=(n/2+1)-1;
        printf("Enter number:");
        for( i = 0; i < n; i++)
        {
            scanf("%d",&insert[i]);
        }

        printf("\n%d is the middle element of array\n",insert[md]);
        printf("\nDiffrence between middle and each element of array\n");
        for(i =0; i < n; i++)
        {
            //comapre middle element of each element
            dif=insert[i]-insert[md];
            
            
            printf("\n%d - %d = %d",insert[i],insert[md],dif);
        }
    }
}

    Leave a Reply

    Your email address will not be published.

    Need Help?