[ create a new paste ] login | about

Link: http://codepad.org/zQ96eY0j    [ raw code | output | fork ]

C, pasted on Jan 30:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <stdio.h>

void average(int *quantity,int number,double *avr)
{
	int i,sum=0;
	for(i=0;i<number;i++) sum+= *(quantity+i);
	*avr = ((double) sum)/((double) number);
}

int main(void)
{
	int quantity[]={1, 4, 2, 8, 1, 5};
	double avr;
	average(quantity,6,&avr);
	printf("%f\n",avr);
	return(0);
}


Output:
1
3.500000


Create a new paste based on this one


Comments: