Program to demonstrate standard deviation using function

Write a program to demonstrate standard deviation using function

#include<stdio.h>
#include<conio.h>
#include<math.h>

float mean(int a[],int n);
float std(int a[],int n,float m);

void main()
{
            float m,sd;
            int n,a[10],i;
            clrscr();
            printf(“\nenter the number of values\n”);
            scanf(“%d”,&n);
            printf(“\n enter the elements\n”);
            for(i=0;i<n;i++)
                        scanf(“%d”,&n);
            m=mean(a,n);
            printf(“mean=%f\n”,m);
            sd=std(a,n,m);
            printf(“\n sd=%f”,sd);
            getch();
}

float mean (inta[],intn)
{
            float f;
            int sum=0;
            for(i=0;i<n;i++)
                        sum=sum+ a[i];
            f=(float)sum/n;
            return f;
}

float std(int a[],int n,float m)
{
            int i;
            float std,sum=0.0,d;
            for(i=0;i<n;i++)
            {
                        d=a[i]-m;
                        a=d*d;
                        sum=sum+d;
            }
            sd=sqrt(sum\n);
            return sd;
}


Post a Comment