A program to find maximum from an array using pointers
C Programming Language 101
- Write a program to find maximum from an array using pointers
Program
#include <stdio.h>
void main()
{
int a[30], n, i, *p, max = 0;
printf("Enter how many numbers you want to input: ");
scanf("%d", &n);
p = a;
printf("\nEnter numbers:\n");
for (i = 0; i < n; i++)
{
scanf("%d", p + i);
}
for (i = 0; i < n; i++)
{
if (max < (*(p + i)))
{
max = (*(p + i));
}
}
printf("Maximum = %d", max);
printf("\n");
}
Result
Enter how many numbers you want to input: 3
Enter numbers:
1 2 3
Maximum = 3
Last Updated on
Comments