this program will print smallest numbers from 10 entered numbers by user.So, how it works? I have 2 integers and 1 integer array.after clrscr(); program will scan 10 integers from user and it will be stored in array named n.then num=n[0]; is because when program will start checking from first number to last number and obviously before checking and comparing second number we want some value which is number 1 which is n[0] and if the program finds n[1]<n[0] then new value of num will be value of n[1] then this loop will be continued till n[9] and at last program will print value of num which is smallest.Now let us see program.
Program:
#include<stdio.h>
#include<conio.h>
main()
{
int n[9],num,i;
clrscr();
for(i=0;i<=9;i++)
{
printf("Enter number %d: ",i+1);
scanf("%d",&n[i]);
}
num=n[0];
for(i=0;i<=9;i++)
{
if(n[i]<num)
{
num=n[i];
}
}
printf("\nSmallest number is %d",num);
getch();
}
Output:
Program:
#include<stdio.h>
#include<conio.h>
main()
{
int n[9],num,i;
clrscr();
for(i=0;i<=9;i++)
{
printf("Enter number %d: ",i+1);
scanf("%d",&n[i]);
}
num=n[0];
for(i=0;i<=9;i++)
{
if(n[i]<num)
{
num=n[i];
}
}
printf("\nSmallest number is %d",num);
getch();
}
Output: