Display smallest number among array elements - C

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


Share on Google Plus

About Nepali Xoro

Interested in Information Technology, Spreading Knowledge for Nepalease IT Students."Loves Traveling", Listen Music and Surfing web.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment