Write a program in C using pointers to display the sum and average of numbers from m to n.
Answers
Answer:
Explanation :#include <stdio.h>
#include <conio.h>
void main()
{
int n,*p,sum=0,i;
float avg;
clrscr();
printf("\nHOW MANY NUMBERS: ");
scanf("%d",&n);
p=(int *) malloc(n*2);
if(p==NULL)
{
printf("\nMEMORY ALLOCATION UNSUCCCESSFUL");
exit();
}
for(i=0;i<n;i++)
{
printf("\nENTER NUMBER %d: ",i+1);
scanf("%d",(p+i));
}
for(i=0;i<n;i++)
sum=sum+*(p+i);
avg=(float)sum/n;
printf("\nTHE AVERAGE OF THE NUMBERS IS %0.2f",avg);
getch();
}
Answer:
written below-
Explanation:
* C Program to to find the mean of n number using pointer *\
# include < stdio.h >
int main( )
{
int a[20], n, i, sum=0 ;
float mean ;
int *ptr ;
printf(" How many Numner you want to enter: ") ;
scanf("%d ",& n) ;
printf("\n Enter the number : \n") ;
for (i = 0; i < n ; i++ )
{
scanf("%d ",& a[i]) ;
ptr++ ;
}
ptr = & a[0] ;
printf(" \n Element in array are :\n ") ;
for (i = 0; i < n ; i++ )
{
printf("\t %d ",( *ptr )) ;
sum = sum + *ptr ;
ptr++ ;
}
mean = sum / n ;
printf("\n Mean of %d Numbers are : %f ",n, mean) ;
return ( 0 );
}
#SPJ2