# Thread: Help with a small program

1. ## Help with a small program

I need some help writing a program that inputs three different integers from the keyboard, then prints the sum, the average, the product, the smallest and the largest of these numbers. Using only the single-selection form of the IF statement. If someone could help me it would be greatly appreciated.

2. sum = a + b + c
average = (a + b + c) / 3
product = a*b*c
smallest: assume first is smallest, and then test, using if, and make one of the others the smallest, if so

3. Code:
```#include <stdio.h>

void main()
{
int a,b,c,product;
float average,sum;

printf("\n\tInteger 1: ");
scanf("%i",&a);
printf("\n\tInteger 2: ");
scanf("%i",&b);
printf("\n\tInteger 3: ");
scanf("%i",&c);

sum=a+b+c;
average=sum/3;
product=a*b*c;

printf("\n\n\tSum: %.0f",sum);
printf("\n\tAverage: %.3f",average);
printf("\n\tProduct: %i",product);
}```
I was too lazy to type out the Smallest/Largest part of the program...read his above post...you can figure it out.

4. >void main()
Never use void main, the result is undefined. The proper declaration for main is either int main ( void ) or int main ( int argc, char *argv[] )

-Prelude

5. I was about to say the same thing, Prelude.

I hope they didn't teach you that in programming class, SavesTheDay.

6. they taught ME that in programming class! void main...*shakin my head* shame u can learn more on the net for \$19.99/mo. than I learn @ school for \$12,000/year lol

*dust*

7. >they taught ME that in programming class!
You'll be hard pressed to find a good class on C, very few teachers actually know how to program correctly and portably. I walked out on a class and dropped out of it the next day because the instructor recommended use of fflush ( stdin ) to clear the garbage left behind by scanf.

Right idea, wrong method. Hopefully I screamed at him enough to change his mind about fflushing input streams ;D And books are the same way, you have to look pretty hard to find a book on C that is actually worth the exorbitant prices they ask for.

-Prelude

8. Prelude ... just wondering if you know of any good C books you would recommend,

"that is actually worth the exorbitant prices they ask for"

cause i am having a hard time finding a good one thats worth paying for, and reading. as you just pointed out.

Any suggestions would be helpful, thx

9. The C Programming Language is worth the money, as are
Pointers on C by Kenneth Reek
Algorithms in C by Robert Sedgewick
Writing Solid Code by Steve Maguire
Expert C Programming by Peter Van Der Linden
C Unleashed by Richard Heathfield, Lawrence Kirby, et al.
The C Standard Library by P. J. Plauger
and I've been told that C How to Program by Deitel and Deitel is good, though it's the most expensive of all of them.

C Unleashed is a personal favorite of mine, partly because I know most of the authors personally
Algorithms in C is an absolute must, no questions asked. Though it is hard to follow if you don't have a firm grasp of the basic syntax.
Writing Solid Code is good for writing clean and bugless code, the constructs offered are very useful.
Expert C Programming would be a good read even if it didn't contain information that normally would take years of hard core experience to learn.
Pointers on C is a wonderful introductory book and reference material. It explains pointers well and early, which are two items that make it a keeper. I find this one useful even now, being well past the introductory phase.
The C Programming Language...written by the creator of the language, need I say more?
The C Standard Library is excellent for both learning how to use the standard library to its fullest as well as reading about how each function is implemented with full source code! I don't even have to tell you how useful that is.

-Prelude

10. Prelude ... thanks for the reply, and the good variety of seemingly complete and beneficial books to check into.

Im sure this list will help myself, and others, now and in the future.

11. I have C: How to program by Deitel and Deitel, and i luv the exercises in EACH chapter, though out of many times i have to seek help, but i find that it's through doing exercises that u learn, not plainly by reading .

To Prelude:
Did u actually meet the authors? Just curious, how did u meet them?

12. I've met a couple of them at conventions and similar functions, but for the most part through the net by email, chat and forums. The easiest way to meet an author is to go onto Usenet and post. Richard Heathfield, Lawrence Kirby and Ben Pfaff are all regular contributers to comp.lang.c

-Prelude