[C] King exercise 6.1

From: Gary Schenk (gwschenk_at_fuzz.socal.rr.com)
Date: 03/31/04

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

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>

    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

Relevant Pages

  • Re: [C] King exercise 6.1
    ... >programming is from taking a Perl course from the local university ... >extended education course. ... >I am reading C Programming: ... >when the user enters a zero or negative number. ...
  • A question for developers
    ... shell/awk stuff if you want to call that programming). ... I normally use Poderosa (a tabbed SSH client) to ... easy way to flip back and forth (a virtual 'tab' system, ... then I very much welcome your feedback. ...
  • Re: Design by Contract or Design by Test?
    ... >> SPARK language and its capability to do various forms of static ... Now I am curious whether these two programming techniques ... Coding should be subordinate to, and implement the system design plan, ... programmer feedback, dadabase admin feedback, network people feedback, ...
  • Re: Implementing strstr
    ... exercises they contain. ... and study abilities I'd expect from first-year college students C, ... Most of it's honestly pretty obvious if you do any programming and ... I continue to push updates to the public git tree before running them ...
  • Re: Help me come up with a few and simple programming challenges
    ... functional programming, and in real life actual algorithmic development is rather rare; most programming is more about data structures and communication. ... because I don't really care to do some toy programs for funny toy exercises. ... Maybe in some cases stuff like that could be applied to real-life problems, but I've never even heard of anything like that, so I don't bother. ...