pls help asap. ty..
In turbo c... write a program that will search for the smallest value in an array of integers of length 10?
simple
void main()
{
int num[10];
int i,small=0;
//code input here
for(i=0;i%26lt;10;i++)
{
if(small%26gt;num[i])
small=num[i];
}
//output
printf("%d\n",small);
}
Reply:#include%26lt;conio.h%26gt;
#include%26lt;stdio.h%26gt;
void main()
{
int a[10],min,i;
printf("Enter 10 values:\n");
scanf("%d",%26amp;a[0]);
min=a[0]; // to make program applicable in all situation.
/*if we consider min=0 it is not applicable in negative and numbers hibher than zero. try this and u will find that i m right. */
for( i = 1;i%26lt;10;i++)
{
scanf("%d",%26amp;a[i]);
if(a[i]%26lt;min)
min=a[i];
}
printf("Minimum of ten numbers is:%d",min);
getch();
}
hope it helps.
bye.
Reply:#include %26lt;stdio.h%26gt;
int main()
{
int array[10] = {10, 52, 61, 1, 17, 31, 100, 84, 99, 63};
int smallest=0xffff, i;
//For turbo c (integer is 2 bytes) maximum value of int is 0xffff
for(i=0;i%26lt;10;i++) if(array[i]%26lt;smallest) smallest=array[i];
printf("Smallest = %d\n", smallest);
return 0;
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment