
02-Mar-2004, 22:01
|
|
New Member
|
|
Join Date: Mar 2004
Posts: 8
|
|
|
Please Help, problems writing newbie C program ReREVISED
/* Group Project pg 299, # 58
written by:
3-3-04
This program reads a list of integers from the keyboard and creates the following information:
find and print the sum and the average of the integers, find and print the largest and smallest
integer, print a boolean true or false if some of them are less than 20, print a boolean
true or false if all of them are betrween 10 and 90.*/
#include <stdio.h>
/* Prototype Declarations*/
int main (void)
{
/*Local Definitions*/
int num = 0;
int secondnum = 0;
int sum = 0;
float avg = 0;
float largest = 0;
float smallest = 0;
float boolone = 0;
float booltwo = 0;
float boolean = 0;
int totalintegers = 0;
/*Statememts*/
/*Main*/
printf(" Please enter numbers: <return> : Enter 99999 to stop\n");
do
{
scanf("%f",&num);
totalintegers ++;
secondnum += num;
sum = num + num;
avg = sum / totalintegers;
if (num > num)
largest = num;
else
smallest = num;
if (num < 20 )
boolone = 1;
else
boolone = 0;
if (num > 10 && num < 90)
booltwo = 1;
else
booltwo = 0;
}
while (num!=99999);
printf(" The number of integers is: %d\n",totalintegers);
printf(" The sum of the integers is: %d\n",sum);
printf(" The average of the intergers is: %f\n",avg);
printf(" The smallest integer is: %f\n",smallest);
printf(" The largest integer is: %f\n",largest);
if (boolone !=0)
printf(" True, some of the integers are less than twenty\n");
else
printf(" False, none of the integers are less than twenty\n");
if (booltwo!=0)
printf(" True, all of the integers are between 10 and 90\n");
else
printf(" False, none of the integers are between 10 and 90\n");
return 0;
}
/* end main*/
Last edited by dsmith : 02-Mar-2004 at 22:23.
Reason: Added C syntax highlighting
|