Monday 2 July 2012

Find minimum number in an array in C


Code - 


//_Program reads 5 numbers and find the minimum out of them .... (Array Example)__

//__________Include Header Files___________

#include<stdio.h>

#include<conio.h>

//____________Mainly used for the getch() function______________

int main()

//_____This is the function from where the program execution starts____

{
int number[5], temp = 0, minimum = 0;

//_________Array index starts from 0 and runs till (Size - 1)_______________

printf("\n\n\t\t________Finding the minimum out of 5 numbers_________\n\n");

for(temp = 0; temp < 5 ; temp++)

//__________Looping construct from 0 to 4 i.e. 5 times___________

{
printf("\n  Enter the %d number - ",temp + 1);

//___________Prompting the user to enter the numbers____________

scanf("%d", &number[temp]);

//_____________Reading the numbers and adding them to array__________
}

minimum = number[0];

//__________Assuming the first number is the minimum number____________

for (temp = 1; temp < 5; temp++)
{
if (number[temp] < minimum)

//______ Checking if the other elements in the array is less than the minimun set______
{
minimum = number[temp];
}
}

printf("\n\n________________________________________________________________________________");

printf("\n\n\t\tMinimum Number :- %d", minimum);

//___________Displaying the lowest number____________

getch();

return 0;

//__Return 0 tells the compiler that program execution has been done without any errors_

}


Follow Us on Facebook -  Assignment Hub

No comments:

Post a Comment