Showing posts with label arrays logics. Show all posts

find the second smallest element in the array


#include<stdio.h>
main()
{
        int a[5] = {66,33,77,11,10};
        int min,smin,i;
        smin = a[0];
        for(i=0;i<=4;i++)
        {
                if(a[i]<min)
                {
                        smin = min;
                        min = a[i];
                }
                if(min<a[i]&&a[i]<smin)
                {
                        smin = a[i];
                }
        }
        printf("the first min number z %d\n",min);
        printf("the second min number z %d\n",smin);
}


op :
the first min number z 10
the second min number z 11
read more →

find the second biggest element in the array



#include<stdio.h>
main()
{
        int a[5] = {55,11,66,77,72};
        int max,min,i;
        int smax,smin;
        max = min = a[0];
        smax = smin = a[0];
        for(i=0;i<=4;i++)
        {
                if(a[i]>max)
                {
                        smax = max;
                        max = a[i];
                }
                if(max>a[i]&&smax<a[i])
                {
                        smax = a[i];
                }
        }
        printf("the first max element z %d\n",max);
        printf("the second max element z %d\n",smax);
}

------------------------------------------------------------------------------------------------------------------------------------------
op:
 the first max element z 77
the second max element z 72
read more →

Biggest and Smallest element in the array


#include<stdio.h>
main()
{
        int a[5] = {55,99,33,22,10};
        int max,min,i;
        max = a[0];
        min = a[0];
        for(i=0;i<=4;i++)
        {
                if(a[i]>max)
                {
                        max = a[i];
                }
                if(a[i]<min)
                {
                        min = a[i];
                }
        }
        printf("the max element z %d\n",max);
        printf("the min element z %d\n",min);
}


op :
the max element z 99
the min element z 10
 







read more →