#include<stdio.h>
#include<math.h>
float *ptr;
void gettheset(int b)
{
float st[b];
int i;
printf("\nEnter the elements of the set\n");
for(i=0;i<b;i++)
{
scanf("%f",&st[i]);
}
for(i=0;i<b;i++)
{
printf("\t%f\t",st[i]);
}
ptr=st;
printf("\nthe address of the pointer ptr is %p",ptr );
}
float mean(int d)
{
float m=0;
int j;
for(j=0;j<d;j++)
{
m=m+(*(ptr+j));
}
m=m/d;
return m;
}
void variance(int e, float sd)
{
int k;
printf("\nthe address of the pointer ptr(var1) is %p",ptr );
for(k=0;k<e;k++)
{
*(ptr+k)=sd-*(ptr+k);
*(ptr+k)=(*(ptr+k))*(*(ptr+k));
}
printf("\nthe address of the pointer ptr(var2) is %p",ptr );
float v=0;
for(k=0;k<e;k++)
{
v=v+(*(ptr+k));
}
v=(v/e);
printf("The variance of the set is %f",v);
printf("\nthe address of the pointer ptr(var3) is %p",ptr );
}
main()
{
int a,check;
char c;
printf("Give the size to the array/set ");
while(1)
{
check=scanf("%d",&a);
c=getchar();
if(check!=1||c!='\n')
{
printf("Invalid size of the array. Type again\n");
while((c=getchar())!='\n');
}
else
{
break;
}
}
gettheset(a);
float mn;
mn=mean(a);
printf("\nThe mean of the set if %f\n",mn);
variance(a,mn);
}
float *ptr;
void gettheset(int b)
{
float st[b]; //local variable
//...
ptr=st; //pointing to local variable
printf("\nthe address of the pointer ptr is %p",ptr );
}//`st' dies
//ptr is pointing to garbage