English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

if series of numbers are entered by the user(don't know how many), How do I use a loop to figure out the average,largest,and smalles number?

2007-03-26 13:23:42 · 1 answers · asked by jkim972 3 in Computers & Internet Programming & Design

1 answers

int n;
int nMax ,nMin,nSum,nNum;
nMax = nMin = -1;
nSum = nNum = 0;
printf ("Enter a numbers 0 to stop");
repeat
{
scanf("%d",&n);
nNum++;
nSum += n;
if (nMax == nMin) and (nMax = -1)
{
nMax = nMin = n;
}

if (nMax > n)
nMax = n;
if (nMin=-1)
nMin = n;
}
until (n==0);

nNum--;

if (nNum<>0)
{
printf("Sum of %d numbers is %d \n and average is %f",nNum,nSum,nSum/nNum);
printf("Max of numbers is %d Min of numbers is %d ",nMin,nMax);

}

2007-03-26 14:24:02 · answer #1 · answered by askMahesh 3 · 0 0

fedest.com, questions and answers