Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

void find_three_Smallest(int arr[], int arr_size,int *smallest,int *second_small

ID: 670440 • Letter: V

Question

void find_three_Smallest(int arr[], int arr_size,int *smallest,int *second_smallest,int *third_smallest )

{ int i, first, second,third;

/* There should be atleast two elements */ if (arr_size < 2)

{ printf(" Invalid Input ");

return; }

first = second = INT_MAX;

for (i = 0; i < arr_size ; i ++)

{

/* If current element is smaller than first then update both first and second */

if (arr[i] < first)

{ second = first; smallest= arr[i]; }

/* If arr[i] is in between first and second then update second */

else if (arr[i] < second && arr[i] != smallest)

second_smallest = arr[i];

else if (arr[i] < third && arr[i] != smallest&& arr[i] != second_smallest) third_smallest = arr[i]; }

if (second == INT_MAX)

printf("There is no second smallest element ");

else printf("The smallest element is %d and second Smallest element is %d third Smallest element is %d ", smallest, second_smallest,third_smallest); }

How to write main function?

Explanation / Answer

int main()

{

int arr[3] = {1,2,3};

int smallest,second_smallest,third_smallest;

  

find_three_Smallest(arr,3,&smallest,&second_smallest,&third_smallest);

  

return 0;

}