3. Ms. Seena has brought 10 items and she wants to print the item with minimum and maximum cost. Write a software program to do it.
#include <stdio.h>
#include <stdlib.h>
int main()
{
int items[10], min, max;
for (int i = 0; i < 10; i++) {
printf("Enter the price for item %d: ", i+1);
scanf("%d", &items[i]);
}
min = max = items[0];
for (int i = 1; i < 10; i++) {
if (min > items[i]) {
min = items[i];
}
if (max < items[i]) {
max = items[i];
}
}
printf("The minimum price is %d.\n", min);
printf("The maximum price is %d.\n", max);
return 0;
}
Enter the price for item 1: 230
Enter the price for item 2: 560
Enter the price for item 3: 190
Enter the price for item 4: 600
Enter the price for item 5: 100
Enter the price for item 6: 549
Enter the price for item 7: 32
Enter the price for item 8: 45
Enter the price for item 9: 98
Enter the price for item 10: 230
The minimum price is 32.
The maximum price is 600.
Comments
Leave a comment