Reputation: 485
I have written the following code:
#include <stdio.h>
/* max_number.c: outputs the largest number of five numbers entered */
void main(void) {
int i, num, max;
for (i = 1; i <= 5; i++) {
printf("Enter a number: ");
scanf("%d", &num);
if (num >= max)
max = num;
}
printf("The maximum number is %d\n", max);
}
When I run the program with any type of data I continually get "The maximum number is 14". Can someone please point me in the direction of what I am doing wrong? Thank you!
Upvotes: 0
Views: 44