Logo 
Search:

C Programming Articles

Submit Article
Home » Articles » C Programming » BeginnersRSS Feeds

Passing of arrays to a function

Posted By: Adali Fischer     Category: C Programming     Views: 4247

Passing of arrays to a function.

Code for Passing of arrays to a function in C Programming

#include     <math.h>                                       
   #define SIZE    5                          
   float std_dev(float a[], int n);
   float mean (float a[], int n);
   main( )                                                     
   {
        floatvalue[SIZE];
        int i;                                                 
                                                               
        printf("Enter %d float values\n", SIZE);               
        for (i=0 ;i < SIZE ; i++)                              
            scanf("%f", &value[i]);                            
        printf("Std.deviation is %f\n", std_dev(value,SIZE));  
   }                                                           
   float std_dev(float a[], int n)                                          
   {    int i;                                                 
        float x, sum = 0.0;                            
        x = mean (a,n);                                        
        for(i=0; i < n; i++)                                    
            sum += (x-a[i])*(x-a[i]);                              
        return(sqrt(sum/(float)n));                            
   }                                                           
   float mean(float a[],int n)                                             
   {                                                           
        int i ;                                                
        float sum = 0.0;                                       
        for(i=0 ; i < n ; i++)                                 
           sum = sum + a[i];                                   
        return(sum/(float)n);                                  
   } 
                                                          


Output     

Enter 5 float values                                        
           35.0 67.0 79.5 14.20 55.75   
                               
            Std.deviation is 23.231582 
  
Share: 


Didn't find what you were looking for? Find more on Passing of arrays to a function Or get search suggestion and latest updates.

Adali Fischer
Adali Fischer author of Passing of arrays to a function is from Frankfurt, Germany.
 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!