Hi, I have hit a brick wall with my lab assignment.
The source code bellow is all included in main(), however, we are suppose to use functions as much as possible.
My first headache is...how do you call infinite parameters in a function.
The goal is to write a program that reads a list of integers(no limit) from the keyboard and return the followings.
#of integers, sum of integers, average of integers, smallest & largest integers, and print boolean (T/F) if at least one # is largest)
{code}
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#define TRUE 1
#define FALSE 0
int main(void)
[ int sum=0, count=0, nums;
int smallest = INT_MAX;
int largest = INT_MIN;
float avg;
bool belowTwenty = FALSE;
bool btwnTenNinty = TRUE;
printf("Enter numbers with <return> (99999 to stop)\n");
scanf("%d",&nums);
while(nums != 99999)
[ sum += nums;
count++;
// scanf("%d",&nums);
if (nums < smallest)
smallest = nums;
if (nums > largest)
if(nums!=99999)
]
largest = nums;
]
scanf("%d",&nums);
]
avg = (sum /count);
belowTwenty = (nums < 20);
btwnTenNinty = (10<= nums && nums >= 90) ;
printf("\nThe number of integers is:\t%3d\n",count);
printf("The sum of the integers is:\t%4d\n",sum);
printf("The average of the integers is:\t%03.2f\n",avg);
printf("The smallest integer is:\t%d\n", smallest);
printf("The largest integer is: %d\n", largest);{/code}
The source code bellow is all included in main(), however, we are suppose to use functions as much as possible.
My first headache is...how do you call infinite parameters in a function.
The goal is to write a program that reads a list of integers(no limit) from the keyboard and return the followings.
#of integers, sum of integers, average of integers, smallest & largest integers, and print boolean (T/F) if at least one # is largest)
{code}
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#define TRUE 1
#define FALSE 0
int main(void)
[ int sum=0, count=0, nums;
int smallest = INT_MAX;
int largest = INT_MIN;
float avg;
bool belowTwenty = FALSE;
bool btwnTenNinty = TRUE;
printf("Enter numbers with <return> (99999 to stop)\n");
scanf("%d",&nums);
while(nums != 99999)
[ sum += nums;
count++;
// scanf("%d",&nums);
if (nums < smallest)
smallest = nums;
if (nums > largest)
if(nums!=99999)
]
largest = nums;
]
scanf("%d",&nums);
]
avg = (sum /count);
belowTwenty = (nums < 20);
btwnTenNinty = (10<= nums && nums >= 90) ;
printf("\nThe number of integers is:\t%3d\n",count);
printf("The sum of the integers is:\t%4d\n",sum);
printf("The average of the integers is:\t%03.2f\n",avg);
printf("The smallest integer is:\t%d\n", smallest);
printf("The largest integer is: %d\n", largest);{/code}
Last edited: