Re: Beginning programmer... I need some help.
- From: "Vladimir S. Oka" <novine@xxxxxxxxxxxxxxx>
- Date: Sun, 5 Feb 2006 21:21:05 +0000 (UTC)
bmlclemson08 wrote:
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 main(void)
is better, as it spells it out for all to see...
{
int current_in, largest_so_far, counter;
printf ("Enter your numbers:\n");
scanf ("%d", &largest_so_far);
for (counter = 2; ; counter=counter+1)
This is a never-ending loop. I suspect that's not what you want.
{
scanf ("%d", ¤t_in);
Using fgets()/sscanf() combination is safer...
if (largest_so_far<current_in)
largest_so_far = current_in;
else
largest_so_far = largest_so_far;
The `else` part is superfluous.
}
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.
Hint: ask user for a number of integers they want to enter; store that
in your `counter`; while `counter` is > 0 read in number, determine if
it's largest so far, decrement `counter`, rinse, repeat; output
`largest_so_far`.
Cheers
Vladimir
--
You know it's going to be a bad day when you want to put on the clothes
you wore home from the party and there aren't any.
.
- References:
- Beginning programmer... I need some help.
- From: bmlclemson08
- Beginning programmer... I need some help.
- Prev by Date: Re: Float to int type casting?
- Next by Date: Re: Beginning programmer... I need some help.
- Previous by thread: Beginning programmer... I need some help.
- Next by thread: Re: Beginning programmer... I need some help.
- Index(es):
Relevant Pages
|