Advertisement
joharido

Untitled

Mar 13th, 2019
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.53 KB | None | 0 0
  1. /***************************************
  2. * CSE2031 – Lab 5 *
  3. * Author:  Johari, Donya
  4. * Email: Your email address djohari37@gmail.com
  5. * eecs_num: joharido
  6. * Yorku #: 215491079
  7. ****************************************/
  8. /* Passing an array to a function. */
  9.  
  10. #include <stdio.h>
  11. #include <string.h>
  12. #include <stdlib.h>
  13.  
  14. #define MAX 20
  15.  
  16.  
  17. int largest(int * x);
  18. void display(int *arr);
  19.  
  20.  int main(int argc, char *argv[])
  21.  {
  22.      int array[MAX], count;
  23.  
  24.      /* Input MAX values from the keyboard. */
  25.      int i;  count=0;
  26.      while ( scanf("%d", &i) != EOF){
  27.         *(array + count) = i; // store in array[count]
  28.         count++;
  29.      }
  30.      *(array + count) = '\0';
  31.      int p = scanf("%d", &i);
  32.      printf("%d\n", count);
  33.  
  34.       /* Call the function and display the return value. */
  35.       printf("Inputs: ");
  36.       display(array);
  37.  
  38.      
  39.      //int largestVal = largest(array, count);
  40.      printf("\nLargest value: %d\n", largest(array));
  41.      
  42.      return 0;
  43.  }
  44.  
  45.  /* display a int array */
  46.  
  47.  void display(int *arr)
  48.  {
  49.    int i = 0;
  50.     int zero = 0;
  51.    
  52.      while (*arr != '\0'){
  53.         //  if(*arr == zero){
  54.         //      printf("%d ", *arr);
  55.         //  }
  56.          printf("%d ", *arr);
  57.          arr++;
  58.      }
  59.  }
  60.  
  61.  
  62. /* Function largest() returns the largest value */
  63.  /* in an integer array */
  64.  
  65.  int largest(int * arr)
  66.  {
  67.      int max = 2;
  68.    
  69.      while (*arr != '\0'){
  70.          if (max < *arr){
  71.              max = *arr;
  72.          }
  73.          arr++;
  74.      }
  75.      return max;
  76.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement