/*WAP to find maximum element in the entered array USING POINTER.*/
#include<stdio.h>
#include<conio.h>
void main()
{
long array[100], *maximum, size, c, location = 1;
printf("Enter the number of elements in array\n");
scanf("%ld", &size);
printf("Enter %ld integers\n", size);
for ( c = 0 ; c < size ; c++ )
scanf("%ld", &array[c]);
maximum = array;
*maximum = *array;
for (c = 1; c < size; c++)
{
if (*(array+c) > *maximum)
{
*maximum = *(array+c);
location = c+1;
}
}
printf("Maximum element found at location %d and it's value is %d.\n", location, *maximum);
getch();
}
Expected Output:
Enter the number of elements in array: 5
35
43
25
78
45
Maximum element is present at location 4 and it's value is 78.
#include<stdio.h>
#include<conio.h>
void main()
{
long array[100], *maximum, size, c, location = 1;
printf("Enter the number of elements in array\n");
scanf("%ld", &size);
printf("Enter %ld integers\n", size);
for ( c = 0 ; c < size ; c++ )
scanf("%ld", &array[c]);
maximum = array;
*maximum = *array;
for (c = 1; c < size; c++)
{
if (*(array+c) > *maximum)
{
*maximum = *(array+c);
location = c+1;
}
}
printf("Maximum element found at location %d and it's value is %d.\n", location, *maximum);
getch();
}
Expected Output:
Enter the number of elements in array: 5
35
43
25
78
45
Maximum element is present at location 4 and it's value is 78.