B
bmlclemson08
Hey if anyone could I need to find out how to write a program that will
read in any number of integers, including none, and determine which is
the largest integer. The part i can't figure out is getting the
program to read any number of integers. Any ideas at all would be
wonderful. here's the code for what i have so far.
#include <stdio.h>
int main ()
{
int current_in, largest_so_far, counter;
printf ("Enter your numbers:\n");
scanf ("%d", &largest_so_far);
for (counter = 2; ; counter=counter+1)
{
scanf ("%d", ¤t_in);
if (largest_so_far<current_in)
largest_so_far = current_in;
else
largest_so_far = largest_so_far;
}
printf ("The largest number is %i.\n", largest_so_far);
return 0;
}
All variables and suuch were determined in my class. I'm guessing my
problem is in the for statement, but I can't figure it out. Thanks
again for any help.
read in any number of integers, including none, and determine which is
the largest integer. The part i can't figure out is getting the
program to read any number of integers. Any ideas at all would be
wonderful. here's the code for what i have so far.
#include <stdio.h>
int main ()
{
int current_in, largest_so_far, counter;
printf ("Enter your numbers:\n");
scanf ("%d", &largest_so_far);
for (counter = 2; ; counter=counter+1)
{
scanf ("%d", ¤t_in);
if (largest_so_far<current_in)
largest_so_far = current_in;
else
largest_so_far = largest_so_far;
}
printf ("The largest number is %i.\n", largest_so_far);
return 0;
}
All variables and suuch were determined in my class. I'm guessing my
problem is in the for statement, but I can't figure it out. Thanks
again for any help.