[C] King exercise 6.1
From: Gary Schenk (gwschenk_at_fuzz.socal.rr.com)
Date: 03/31/04
- Next message: Pete Vidler: "Re: [C] King exercise 6.1"
- Previous message: Mike Wahler: "Re: [OT] "thx" (was: [C] whats the difference between "char" and "Char" ?)"
- Next in thread: Pete Vidler: "Re: [C] King exercise 6.1"
- Reply: Pete Vidler: "Re: [C] King exercise 6.1"
- Reply: Leor Zolman: "Re: [C] King exercise 6.1"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 31 Mar 2004 19:00:22 GMT
I am a lone student attempting to learn C. My only real experience
programming is from taking a Perl course from the local university
extended education course. I know no programmers and need some
feedback.
I am reading C Programming: A Modern Approach. I'm finding it to be an
excellent book, far superior to my first C book "C for Dummies". I've
done all the exercises and think they are well thought out.
In chapter 6 things are getting more complicated and I'd like some
feedback from folks who know what they are doing.
Exercise 6.1 asks you to write a program which displays the largest
of a series of numbers entered by the user. The program must terminate
when the user enters a zero or negative number.
This seems to work, but I wonder is there a better way?
#include <stdio.h>
main()
{
float n, input;
printf("\n\n\nFind a Big Number\n\n");
printf("Enter a series of numbers or 0 to quit: ");
scanf("%f", &input);
n = input;
while ( input > 0 ) {
printf("Enter a number: ");
scanf("%f", &input);
if ( input > n ) {
n = input;
}
}
printf("the largest number entered was: %f\n", n);
}
Thanks for the help!
-- Gary W. Schenk remove "fuzz" to reply
- Next message: Pete Vidler: "Re: [C] King exercise 6.1"
- Previous message: Mike Wahler: "Re: [OT] "thx" (was: [C] whats the difference between "char" and "Char" ?)"
- Next in thread: Pete Vidler: "Re: [C] King exercise 6.1"
- Reply: Pete Vidler: "Re: [C] King exercise 6.1"
- Reply: Leor Zolman: "Re: [C] King exercise 6.1"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|