C Program to find average of n numbers.

Posted: January 19, 2012 in Lab 2
#include<stdio.h>
#include<stdlib.h>
void avg(int *,int);
void avg(int *arr,int n)
{
	int s=0,i;
	for(i=0;i<n;i++)
		s=s+*arr++;
	printf("Sum = %d\n Avg= %d\n",s,s/n);
}
int main()
{
	int n,*arr,i;
	printf("Enter the nos of elements\n");
	scanf("%d",&n);
	arr=(int *)malloc(sizeof(int)*n);
	printf("Enter elements\n");
	for(i=0;i<n;i++)
		scanf("%d",(arr+i));
	avg(arr,n);
	return 0;
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s