I have been working on this program and am getting nowhere fast. The program returns the maximum value as 0 each time. At this point I am lost and have probably done more damage than good.
The program should ask the user to enter 20 integers and return the largest number. I would greatly appreciate any help.
Code:#include <stdio.h> int Max_Num(int[]); /* Function prototype*/ main() { int num[21]; int number; int max; printf("\nPlease enter 20 numbers.\n\n"); for (number = 0; number < 20; ++number) { printf("\nEnter the number for %d:", number +1); scanf("%d", &num[number]); } max = Max_Num(num); printf("\nThe max interger was %d", num [max]); return 0; } /* Function Header*/ int Max_Num(int num[]) { int temp; int max = 0; for (temp = 0; temp <=20; ++temp) { if (max < num[temp]) max = num[temp]; } return max; }



LinkBack URL
About LinkBacks


