Write a 'C' program to find maximum and minimum element from an array.
Answers
Answered by
3
Hey dear,
You're answer - C programming code
#include <stdio.h>
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++)
Answered by
2
Write C program to find maximum and minimum element in array
Introduction
Write C program to find maximum and minimum element in array
#include <stdio.h>
int main()
{
int arr[100];
int i, max, min, size;
// Reading array sizr & elements in the array
printf("Enter size of the array: ");
scanf("%d", &size);
printf("Enter elements in the array: ");
for(i=0; i<size; i++)
{
scanf("%d", &arr[i]);
}
/* Supposes the first element as maximum and minimum */
max = arr[0];
min = arr[0];
/*
* Finds maximum and minimum in all array elements.
*/
for(i=1; i<size; i++)
{
// Finding max number
//if cuurent element of array is greater than max
if(arr[i]>max)
{
max = arr[i];
}
// Finding min number
// If current element of array is smaller than min
if(arr[i]<min)
{
min = arr[i];
}
}
//Finding the maximum and minimum element
printf("Maximum element is: %d\n", max);
printf("Minimum element is: %d", min);
return 0;
}
Hope it helps you .
Introduction
Write C program to find maximum and minimum element in array
#include <stdio.h>
int main()
{
int arr[100];
int i, max, min, size;
// Reading array sizr & elements in the array
printf("Enter size of the array: ");
scanf("%d", &size);
printf("Enter elements in the array: ");
for(i=0; i<size; i++)
{
scanf("%d", &arr[i]);
}
/* Supposes the first element as maximum and minimum */
max = arr[0];
min = arr[0];
/*
* Finds maximum and minimum in all array elements.
*/
for(i=1; i<size; i++)
{
// Finding max number
//if cuurent element of array is greater than max
if(arr[i]>max)
{
max = arr[i];
}
// Finding min number
// If current element of array is smaller than min
if(arr[i]<min)
{
min = arr[i];
}
}
//Finding the maximum and minimum element
printf("Maximum element is: %d\n", max);
printf("Minimum element is: %d", min);
return 0;
}
Hope it helps you .
Similar questions