Practice Program







  • Program of Minimum element in an array.
  • Solution:
    
    
    void main()
    {
        int a[20],n,i;
        int min = 0;
    
        printf("Enter the number: ");
        scanf("%d",&n);
    
      //taking array elements as input.
        for(i=0;i<n;i++)
        {
            printf("\nEnter the Element: ");
            scanf("%d",&a[i]);
        }
    
        //printing the array elements
        printf("Array Elements are: \n");
        for(i=0;i<n;i++)
        {
            printf("%d\t",a[i]);
    
        }
    
      //Determining the minimum Element.
        for(i=0;i<i++)
        {
            if(a[i] < min){//Comparing each element with min variable.
                    //if element at j index is less the min value than,
                  min = a[i]; //we are assigning  value at j index as new ,
                        //value of variable min and going for the next iteration.
            }
    
        }
    
    
    
       printf("\nMinimum Element is  %d",max);
    
    
    }
    

    Output1
    Enter the number of elements: 5

    Enter the Element:1
    Enter the Element:2
    Enter the Element: 3
    Enter the Element: 4
    Enter the Element:5

    Array Elements are:
    1      2     3     4     5

    Minimum Element is 1

    Output2
    Enter the number of elements: 5

    Enter the Element:6
    Enter the Element:7
    Enter the Element: 8
    Enter the Element: 9
    Enter the Element:10

    Array Elements are:
    6      7     8     9     10

    Minimum Element is 6.

    Output3
    Enter the number of elements: 5

    Enter the Element:11
    Enter the Element:12
    Enter the Element: 13
    Enter the Element: 14
    Enter the Element:15

    Array Elements are:
     11     12     13     14    15

    Minimum Element is 11.








    defining a function 'give_min' which will return maximum element.

    int give_min(int a[],int n)
    {
        int i,min = 0;
    
        for(i=0;i<i++)
        {
            if(a[i] < min){//Comparing each element with min variable.
                    //if element at j index is less than min value than,
                  min = a[i]; //we are assigning  value at j index as new ,
                        //value of variable max and going for the next iteration.
            }
    
        }
    
        return min;
    
    }
    

    Using above define function 'give_min()':
    void main()
    {   int result;
        int a[10] = {1,2,3,4,5,6,7,8,9,10};
        result = give_min(a,10);
    
        printf("Minimum Element is %d",result);
    }
    

    Output1
    Minimum Element is 1.

    Using above define function 'give_min()':
    void main()
    {   int result;
        int a[10] = {5,6,7,8,9,10};
        result = give_min(a,6);
    
        printf("Minimum Element is %d",result);
    }
    

    Output2
    Minimum Element is 5.

    Using above define function 'give_min()':
    void main()
    {   int result;
        int a[10] = {6,7,8,9,10};
        result = give_min(a,5);
    
        printf("Minimum Element is %d",result);
    }
    

    Output3
    Minimum Element is 6.