Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- double difference(double array[], int size);
- int main(void){
- double array[]={123.2,321.21,90.2, 3, 900};
- printf("The difference between the biggest and smallest elements is %f.\n",difference(array, 5));
- return 0;
- }
- double difference(double array[], int size){
- int i;
- float biggest=3;
- float smallest=-3;
- double *ptr;
- ptr=array;
- for(i=0; i<size; i++){
- if (*ptr>biggest){
- biggest=*ptr;
- ptr++;
- }
- }
- printf("The biggest number is %f.\n", biggest);
- for(i=0; i<size; i++){
- if ((*ptr<smallest)){
- smallest=*ptr;
- ptr++;
- }
- }
- printf("The smallest number is %f.\n", smallest);
- return (biggest-smallest);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement