Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* 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 leng);
- 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++;
- }
- //int p = scanf("%d", &i);
- /* Call the function and display the return value. */
- printf("Inputs: ");
- display(array, count);
- //printf("\nLargest value: %d\n", largest(array));
- return 0;
- }
- /* display a int array */
- void display(int *arr, int leng)
- {
- int i = 0;
- while (i < leng){
- printf("%d ", *arr);
- arr++;
- i++;
- }
- }
- /* Function largest() returns the largest value */
- /* in an integer array */
- int largest(int * arr)
- {
- int *ptr, max;
- ptr = arr;
- max = 0;
- int size = sizeof(arr)/sizeof(int);
- while (size >= 0){
- if (*ptr > max){
- max = *ptr;
- }
- ptr++;
- size--;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement