Write a Function 4. Write a program that reads several integers into an array, t
ID: 3551597 • Letter: W
Question
Write a Function
4. Write a program that reads several integers into an array, then finds the largest and smallest values in that array, then prints the values in the elements of the array between where the largest is and where the smallest is, with comma's separating the values. Assume the end of the input is indicated by 0 (which is not stored in the array), and that there will be no more than 25 values. Do not use a function. For example, if the input is 4 9 3 5 8 2 7 6 0, then you should print 3,5, 8. When run from the command line, here's how things should look: Input several integers ending with 0 49 3 5 8 2 7 6 0 3, 5,8Explanation / Answer
#include<stdio.h>
int main()
{
int low=0,high=0,arr[25],i,val,j=-1,min,max;
printf("Input several integers , ending with 0 : ");
while(1)
{j++;
scanf("%d",&val);
if(val==0)
break;
arr[j]=val;
}
min=arr[0];
for(i=1;i<j;i++)
if(min>arr[i])
{min=arr[i];
low=i;
}
max=arr[0];
for(i=1;i<j;i++)
if(max<arr[i])
{max=arr[i];
high=i;
}
printf(" ");
if(low<high)
{
for(i=low+1;i<high;i++)
printf("%d ",arr[i]);
}
else
{for(i=high+1;i<low;i++)
printf("%d ",arr[i]);
}
return 0;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.