1. Engineering
  2. Computer Science
  3. how can i replace arrays that are not in the...

Question: how can i replace arrays that are not in the...

Question details

How can I replace arrays that are not in the main fucntion with pointers. Arrays can only be used in the main function

#include<stdio.h>
#define N 10//n is defined as 10
void max(int a[], int n, int *max);
int main (void)
{
int a [N], i , big,n;
n=0;
printf("Input a series of integers (ended with 0): ",N);
for(i=0;i<N;i++)
{
scanf("%d",&a[i]);
if(a[i]!=0)
n++;
else
break;
}
max(a,n,&big);
printf("Numbers entered by user are: ");
for(i=0;i<n;i++)
printf(" %d",a[i]);
printf("\nThe maximal number of them is: %d\n",big);
return 0;
}
void max(int a[], int n, int *max)
{
int i;
*max=0;
for(i=0;i<n;i++)
{
if(a[i]>*max)
*max=a[i];
}
}

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution