write a c program to find minimum number in a given list of N integers
Answers
Answer:
int a[10],smallest,i;
for(i=0;i<10;i++)
scanf("%d",&a[i]);
smallest=a[0];
for(i=0;i<=10;i++)
{
if ( a[i] <smallest)
{
smallest=a[i];
}
}
printf("\nSmallest number is %d", smallest);
Answer:
The answer is :
#include<stdio.h>
int main() {
int a[], i, num, smallest;
printf("\nEnter no of elements :");
scanf("%d", &num);
//Read n elements in an array
for (i = 0; i < num; i++)
scanf("%d", &a[i]);
//Consider first element as smallest
smallest = a[0];
for (i = 0; i < num; i++) {
if (a[i] < smallest) {
smallest = a[i];
}
}
// Print out the Result
printf("\nSmallest Element : %d", smallest);
return (0);
}
Output :
Enter no of elements :
Smallest Element :
Explanation:
C program to find the smallest of n numbers in a given array
Logic. We start to iterate and then compare all the elements with each other and store the smallest element in the variable named 'small' and then keep comparing till we find the smallest element.
Dry Run of the Program. ...
Program. ...
Output.
Hence, the answer is to Enter no of the elements :
Smallest Element :
#SPJ2