Advertisement
horselurrver

Difference

Aug 4th, 2016
291
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.79 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. double difference(double array[], int size);
  4.  
  5. int main(void){
  6.     double array[]={123.2,321.21,90.2, 3, 900};
  7.     printf("The difference between the biggest and smallest elements is %f.\n",difference(array, 5));
  8.     return 0;
  9. }
  10.  
  11. double difference(double array[], int size){
  12.     int i;
  13.     float biggest=3;
  14.     float smallest=-3;
  15.     double *ptr;
  16.     ptr=array;
  17.     for(i=0; i<size; i++){
  18.         if (*ptr>biggest){
  19.             biggest=*ptr;
  20.             ptr++;
  21.         }
  22.        
  23.     }
  24.     printf("The biggest number is %f.\n", biggest);
  25.    
  26.     for(i=0; i<size; i++){
  27.         if ((*ptr<smallest)){
  28.             smallest=*ptr;
  29.             ptr++;
  30.         }
  31.     }
  32.     printf("The smallest number is %f.\n", smallest);
  33.    
  34.     return (biggest-smallest);
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement