Main Menu

HOME

.Net
ASP
Assembly
C
C++
Delphi
HTML
Java
JavaScript Site
MySQL
PC interface
Powershell
Perl
PHP
VBScript
Visual Basic
XML

US Job listings




   Misc

   Amazon

   Links

    


Running average
 

 

Description

This program calculates a running average based on what a user enters.

Code

/*
This program calculates an average of the numbers entered
*/
#include <stdio.h>

int Average(int i);

int main()
{
int num;
do{

printf("Enter numbers ( -1 to quit ).\n");
scanf("%d",&num);
/*if number is not -1 print the average*/
if(num != -1)
printf("The average is %d", Average(num));
printf("\n");

}while(num>-1);

return 0;
}

int Average(int i)
{
static int sum = 0, count = 0;
sum = sum + i;
count++;
return sum / count;
}

Information

tested using Visual C++ 6

 

 

 

 

Download

average.txt


 




   Sponsors
 

   Software
500 Java Tips E-book
PHP editor
PERL editor
Beginning Java
Beginning Visual Basic
Learn VB.net
Learn VB 6
VB and databases
ASP image library
C++ builder programming
C++ fundamentals

   Source Code
display html source with line numbers(php)
list disk drive information in an excel spreadsheet(VBScript)
Create a MySQL database from PHP(PHP)
File exists(ASP)
perform a DNS query(C Sharp)
move a window(VB)
Simple metatag generator(PHP)
Delete a file(ASP)

    




Copyright © 2003 by programmershelp.co.uk