Tuesday, 2 September 2014

Largest element in array

#include<conio.h>
#include<stdio.h>
main()
{
int arr[10],i,n,j,smallest=9999,count=0,pos,lpos,large=-9999;
printf("enter the size of the array ");
scanf("%d",&n);
printf("enter the element in array ");
for(i=0;i<n;i++)
{
scanf("%d",&arr[i]);
}

for(i=0;i<n;i++)
{
if(arr[i]<smallest)
{
smallest = arr[i];
pos=i;}
else if(arr[i]>large)
{
large=arr[i];
lpos=i;
}
}
printf("the smallest value in this array is %d at the position %d",smallest,pos+1);
printf("\nthe largest value in this array is %d at the position %d",large,lpos+1);
getch();
return 0;
}



No comments:

Post a Comment