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>

#include<conio.h>

void main()

 { 

 int arr[20]; 

 int i, max, min, size;

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();

}




B) Roots of a Quadratic Equation 


#include<stdio.h>
#include<conio.h>
#include<math.h>
void main() 
{
 float a,b,c,root1,root2,desc; 
clrscr(); 
printf("\n Enter values of a,b,c for finding roots of a quadratic eq:\n"); 
scanf("%f%f%f",&a,&b,&c); desc = b*b-4*a*c;
/*checking condition*/ 
if(desc > 0) 
 { 
 root1=-b+sqrt(desc)/2*a; 
 root2=-b-sqrt(desc)/2*a; 
printf("\n*****ROOTS ARE REAL & UN EQUAL *****\n"); 
printf("\nroot1=%.2f\n root2=%.2f",root1,root2); 
 }
 else
 if(desc==0) 
 {
 root1=-b/2*a;
 root2=-b/2*a; 
printf("\n*****ROOTS ARE REAL & EQUAL *****\n"); 
printf("\n root1=%.2f\n root2=%.2f",root1,root2); 
 }
 else
 printf("\n Imaginary Roots."); 
getch(); 

Comments

Popular posts from this blog