Q. Assume that the array have size 10. WAP to request the 10 integers from users store it into array and display the smallest number among the entered number.
#Assignment8No
==>Code goes like this:
int main()
{
int a[10],i,j,temp;
printf("Enter 10 elements of array: ");
for ( i = 0; i < 10; i++)
{
scanf("%d",&a[i]);
}
//for smallest integer
for ( i = 0; i < 9; i++)
{
for ( j = i+1; j < 10; j++)
{
if(a[i] > a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
printf("The smallest integer is: %d \n ",a[0]);
return 0;
}
Output:
If you are using Turbo C++ IDE, then use conio.h in link section after stdio.h
and use getch(); to hold the output screen, just before the end of main function.
If you have any confusion regarding the program, please, comment below.
Happy Coding !
Thank you
Home / array in c /
AssignmentSolutionC /
C Programs /
Smallest number in array
/ Display smallest number among array elements - C
- Blogger Comment
- Facebook Comment
Subscribe to:
Post Comments
(
Atom
)
0 comments:
Post a Comment