In: Computer Science
Write a C program that prompt the user to enter 10 numbers and stores the numbers in an array. Write a function, smallestIndex, that takes as parameters an int array and its size and return the index of the first occurrence of the smallest element in the array.
The main function should print the smallest number and the index of the smallest number.
Code:
#include
int smallestIndex(int a[],int size)
{
int min=9999,pos;
for(int i=0;i
if(a[i]
min=a[i];
pos=i; //storing the index of smallest number in pos.
}
}
return pos;
}
int main()
{
printf("Enter 10 numebrs:\n");
int a[10];
for(int i=0;i<10;i++)
scanf("%d",&a[i]);
int smallindex=smallestIndex(a,10);
printf("The smallest number in the array is:%d ,it is stored in the
index:%d",a[smallindex],smallindex);
return 0;
}
Screenshot:
Output: