Calculating a floating-point average using pointers : Pointer Double « Pointer « C / ANSI-C

Home
C / ANSI-C
1.assert.h
2.Console
3.ctype.h
4.Data Structure Algorithm
5.Data Type
6.Development
7.File
8.Function
9.Language Basics
10.Macro Preprocessor
11.Math
12.math.h
13.Memory
14.Pointer
15.setjmp.h
16.signal.h
17.Small Application
18.stdio.h
19.stdlib.h
20.String
21.string.h
22.Structure
23.time.h
24.wctype.h
C Tutorial
C++
C++ Tutorial
Visual C++ .NET
C / ANSI-C » Pointer » Pointer DoubleScreenshots 
Calculating a floating-point average using pointers

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>

int main()
{
  double *values = NULL;     
  double sum = 0.0;          
  int capacity = 5;          
  int i = 0;                 

  values= (double*)malloc((capacity)*sizeof(double));
  if(values == NULL){
     printf("Memory allocation failed. Terminating program.");
  }
  for(i=0;i<capacity;i++){
     values[i= i;
     printf(" %.2lf",values[i]);
  }
  for(i = ; i<capacity ; i++)
    sum += *(values+i);

  /* Output the average */
  printf("\n The average of the the values you entered is %.2lf.\n", sum/capacity);
  free(values);     /* We are done - so free the memory */
}


 

           
       
Related examples in the same category
1.A function to calculate an averageA function to calculate an average
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.