Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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

ID: 3807893 • Letter: H

Question

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(" The maximal number of them is: %d ",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];
}
}

Explanation / Answer

#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(" The maximal number of them is: %d ",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];
}
}

Sample output:

Input a series of integers (ended with 0): Numbers entered by user are: 1074252772 1074400403
The maximal number of them is: 1074400403

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote