In this we discussed about how to find the smallest element in the array with some approaches and you can also do with more approaches 


the below points mentions we discussed in this article


  • Question
  • sample input
  • Logic
  • solution with loop
  • solution using function
  • Feedback



Question-

Write a C Program to find the smallest element in the array


sample input 

enter the range 4

2 4 6 3

The smallest element is

2 



C Program to find the smallest element in the array


Logic to solve the problem

  • Take an array of some integers then take a variable ( n )  for taking the input how many data the user want to enter then run a for loop to taking the inputs . 
  • Again run another for loop and inside the loop use if condition for checking the small element in the array , Take a variable for comparing the small element,.
  • Then check inside the if the condition that the value that is smaller than that assign it to small and print the small value
  • Then again run a for loop to displaying the array after reversing.


Source Code

#include<stdio.h>
int main()
{
    int n,small;
    printf("Enter the size :\n");
    scanf("%d",&n);
    int arr[100];
    for(int i=0;i<n;i++)
    {
        printf("Enter the element no.\n");
        scanf("%d",&arr[i]);
    }
    for(int i=0;i<n;i++)
    {
        if(small<arr[i])
        small=arr[i];

    }
    printf("The smallest element in the array is : %d",small);
   return 0;
}



Solve by using the function


Source Code

// Write a C program to find the smallest element of a given array of integers
#include <stdio.h>

void small(int arr[], int n)
{
    int small=0;
    for (int i = 0; i < n; i++)
    {
        if (smal < arr[i])
            smal = arr[i];
    }
    printf("The smal element in the array is : %d",large);
}
int main()
{
    int n,smalll=0;
    printf("Enter the size :\n");
    scanf("%d",&n);
    int arr[100];
    for(int i=0;i<n;i++)
    {
        printf("Enter the element no.\n");
        scanf("%d",&arr[i]);
    }
    small(arr, n);
    return 0;
}

Check Out OUR Home page for more information about practice problem

Also check Out

Also check Out Projects for Resume

    click here

Projects on C++


Projects on C


Problems On C


Problems On C++




Problems on TCS paper


1 , 1 , 2 , 3 , 4 , 9 , 8 , 27 , 16 , 81 , 32 , 243 , 64 , 729 , 128 , 2187

click here to know more

0 , 0 , 2 , 1 , 4 , 2 , 6 , 3 , 8 , 4 , 10 , 5 , 12 , 6 , 14 , 7 , 16 , 8


FEEDBACK 

If still you have any doubts please comment below and please share your approaches in the comment to know others and help others