Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /***************************************
- * CSE2031 – Lab 5 *
- * Author: Johari, Donya
- * Email: Your email address djohari37@gmail.com
- * eecs_num: joharido
- * Yorku #: 215491079
- ****************************************/
- /* Passing an array to a function. */
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #define MAX 20
- int largest(int * x);
- void display(int *arr);
- int main(int argc, char *argv[])
- {
- int array[MAX], count;
- /* Input MAX values from the keyboard. */
- int i; count=0;
- while ( scanf("%d", &i) != EOF){
- *(array + count) = i; // store in array[count]
- count++;
- }
- *(array + count) = '\0';
- int p = scanf("%d", &i);
- printf("%d\n", count);
- /* Call the function and display the return value. */
- printf("Inputs: ");
- display(array);
- //int largestVal = largest(array, count);
- printf("\nLargest value: %d\n", largest(array));
- return 0;
- }
- /* display a int array */
- void display(int *arr)
- {
- int i = 0;
- int zero = 0;
- while (*arr != '\0'){
- // if(*arr == zero){
- // printf("%d ", *arr);
- // }
- printf("%d ", *arr);
- arr++;
- }
- }
- /* Function largest() returns the largest value */
- /* in an integer array */
- int largest(int * arr)
- {
- int max = 2;
- while (*arr != '\0'){
- if (max < *arr){
- max = *arr;
- }
- arr++;
- }
- return max;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement