Write in C. Write a C progra entered by the user should be zero or positive0). T
ID: 3908645 • Letter: W
Question
Write in C.
Write a C progra entered by the user should be zero or positive0). The user will finish the input by using the sentinel value of-1. If the user starts by entering the sentinel, as in sample #2, the program should terminate and indicate that no data has been input. n that takes multiple integers from the user and finds the minimum value. The numbers Sample #1 Sample #2 Finding the minimum. . . Finding the minimum. . . Enter integers (1 to finish) Enter integers (-1 to finish) Integer: -1 No data has been entered Integer 44 Integer: 26 Integer: 6 Integer: 32 Integer 51 Integer: 11 Integer: -1 The minimum value is: 6Explanation / Answer
#include <stdio.h>
int main() {
int num, min=-1;
printf("Finding the minimum... ");
printf("Enter integers (-1 to finish) ");
while(1) {
printf("Integer: ");
scanf("%d", &num);
if(num == -1) {
break;
}
if(min == -1 || num < min) {
min = num;
}
}
if(min >= 0) {
printf(" The minimum value is: %d ", min);
} else {
printf(" No data has been entered. ");
}
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.