write a program to find biggest value in the array using pointers in c
Answers
Answered by
2
Hey there!
Here is the answer of your question.
__________________
#include
int main()
{
int array[100], maximum, size, c, location = 1;
printf("Enter the number of elements in array\n");
scanf("%d", &size);
printf("Enter %d integers\n", size);
for (c = 0; c < size; c++)
scanf("%d", &array[c]);
maximum = array[0];
for (c = 1; c < size; c++)
{
if (array[c] > maximum)
{
maximum = array[c];
location = c+1;
}
}
printf("Maximum element is present at location %d and it's value is %d.\n", location, maximum);
return 0;
}
OUTPUT -:
Enter the number of an elements in array
5
Enter 5 integers
4
5
6
8
2
Maximum element is present at location 4 and it's value is 8.
______________________
Hope this helps you!
Here is the answer of your question.
__________________
#include
int main()
{
int array[100], maximum, size, c, location = 1;
printf("Enter the number of elements in array\n");
scanf("%d", &size);
printf("Enter %d integers\n", size);
for (c = 0; c < size; c++)
scanf("%d", &array[c]);
maximum = array[0];
for (c = 1; c < size; c++)
{
if (array[c] > maximum)
{
maximum = array[c];
location = c+1;
}
}
printf("Maximum element is present at location %d and it's value is %d.\n", location, maximum);
return 0;
}
OUTPUT -:
Enter the number of an elements in array
5
Enter 5 integers
4
5
6
8
2
Maximum element is present at location 4 and it's value is 8.
______________________
Hope this helps you!
Answered by
0
Answer:
#include <stdio.h>
int 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 is present at location number %ld and it's value is %ld.\n", location, *maximum);
return 0;
Explanation:
You forget to put * sign in ptr maximum!
now this is the complete right answer!
Similar questions