Lab Record Program No 7
7.Write a C Program to find Minimum and Maximum element in the array and to find Roots of a Quadratic equation.
A) Maximum and minimum of given list of numbers
#include<stdio.h>
clrscr();
printf("\nEnter size of the array: ");
scanf("%d", &size);
printf("\nEnter %d elements of the array: ",size);
for(i=0; i<size; i++)
scanf("%d", &arr[i]);
/* assume the first element as maximum and minimum */
max = arr[0];
min = arr[0];
for(i=1; i<size; i++)
{
/* If current element of array is greater than max */
if(arr[i]>max)
max = arr[i];
/* If current element of array is smaller than min */
if(arr[i]<min)
min = arr[i];
}
printf("\nMaximum element = %d\n", max);
printf("\nMinimum element = %d\n", min);
getch();
}
Comments
Post a Comment