CPPLAB

 1.      Design, develop and execute a program in C to find and output all the roots of a given quadratic equation, for non-zero coefficients.



Summary:

Any quadratic equation has two roots and the roots of the equation can be found using the formula

x = (-b±√discriminant)/2a

                                                       where discriminant = b2-4ac and

a, b,c   are coefficients when the equation is represented in form ax2+bx+c= 0



Hence as per the equation, if discriminant is equal to 0, then the value of both the roots are equal and real. Also to find x, when discriminant is not 0, we need to find square root of disc. When discriminant value is less than 0, the square root of the discriminant is imaginary and hence the roots of the equation are supposed to be imaginary and distinct. When discriminant value is greater than 0, the square root of the discriminant is real and hence the roots of the equation are supposed to be real and distinct.



Algorithm:

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<span lang="EN-IN" style="mso-fareast-font-family: &quot;Times New Roman&quot;; mso-bidi-font-weight: bold"><font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> 1)<span style="font: 7.0pt &quot;Times New Roman&quot;">      <font face="&quot;Times New Roman&quot;,&quot;serif&quot;">Take the inputs i.e. coefficients of the equation, a ,b,c  from the user.

<span lang="EN-IN" style="mso-fareast-font-family: &quot;Times New Roman&quot;; mso-bidi-font-weight: bold"><font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> 2)<span style="font: 7.0pt &quot;Times New Roman&quot;">      <font face="&quot;Times New Roman&quot;,&quot;serif&quot;">Calculate the value of discriminant = b2-4ac

<span lang="EN-IN" style="mso-fareast-font-family: &quot;Times New Roman&quot;; mso-bidi-font-weight: bold"><font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> 3)<span style="font: 7.0pt &quot;Times New Roman&quot;">      <font face="&quot;Times New Roman&quot;,&quot;serif&quot;">Decide whether roots are equal or distinct. If discriminant is equal to 0, then go to step 4, else go to step 5.

<span lang="EN-IN" style="mso-fareast-font-family: &quot;Times New Roman&quot;; mso-bidi-font-weight: bold"><font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> 4)<span style="font: 7.0pt &quot;Times New Roman&quot;">      <font face="&quot;Times New Roman&quot;,&quot;serif&quot;">Calculate x1and x2. x1 = x2 = -b/2a. Print roots are real and equal. Then go to step 8.

<span lang="EN-IN" style="mso-fareast-font-family: &quot;Times New Roman&quot;; mso-bidi-font-weight: bold"><font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> 5)<span style="font: 7.0pt &quot;Times New Roman&quot;">      <font face="&quot;Times New Roman&quot;,&quot;serif&quot;">Decide whether roots are real or imaginary. If discriminant is lesser than 0, roots are imaginary and go to step 6. If discriminant is greater than 0, roots are real and go to step 7.

<span lang="EN-IN" style="mso-fareast-font-family: &quot;Times New Roman&quot;; mso-bidi-font-weight: bold"><font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> 6)<span style="font: 7.0pt &quot;Times New Roman&quot;">      <font face="&quot;Times New Roman&quot;,&quot;serif&quot;">Calculate the roots x1 and x2. X1 undefined =  p+qi and x2 =p-qi where p = -b/2a and q = (√(discriminant*-1))/2a. Print roots are imaginary and distinct.

<span lang="EN-IN" style="mso-fareast-font-family: &quot;Times New Roman&quot;; mso-bidi-font-weight: bold"><font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> 7)<span style="font: 7.0pt &quot;Times New Roman&quot;">      <font face="&quot;Times New Roman&quot;,&quot;serif&quot;">Calculate the roots x1 and x2. X1 undefined =  (-b+√(discriminant))/2a and x2 =(-b-√(discriminant))/2a. Print roots are real and distinct.

<span lang="EN-IN" style="mso-fareast-font-family: &quot;Times New Roman&quot;; mso-bidi-font-weight: bold"><font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> 8)<span style="font: 7.0pt &quot;Times New Roman&quot;">      <font face="&quot;Times New Roman&quot;,&quot;serif&quot;">Print the value of x1 and x2.

<span lang="EN-IN" style="mso-fareast-font-family: &quot;Times New Roman&quot;; mso-bidi-font-weight: bold"><font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> 9)<span style="font: 7.0pt &quot;Times New Roman&quot;">      <font face="&quot;Times New Roman&quot;,&quot;serif&quot;">STOP

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">Examples:

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<span lang="EN-IN" style="mso-fareast-font-family: &quot;Times New Roman&quot;; mso-bidi-font-weight: bold"><font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> a)<span style="font: 7.0pt &quot;Times New Roman&quot;">       <font face="&quot;Times New Roman&quot;,&quot;serif&quot;">if  <font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> a=5, b=10 and c =2, then discriminant = b2-4ac = (10)2-4*5*2 = 100-40 = 60.

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">Since the discriminant is not 0, hence the roots are distinct. Also since discriminant is greater than 0, roots are real. Hence as per step 7,

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">x1 <font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> <font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> = (-b+√(discriminant))/2a = (-10+√60)/2*5 = (-10+7.746)/10 = -2.254/10 = 0.2254.

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">x2 <font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> <font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> = (-b-√(discriminant))/2a = (-10-√60)/2*5 = (-10-7.746)/10 = -17.746/10 = -1.7746.

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<span lang="EN-IN" style="mso-fareast-font-family: &quot;Times New Roman&quot;; mso-bidi-font-weight: bold"><font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> b)<span style="font: 7.0pt &quot;Times New Roman&quot;">       <font face="&quot;Times New Roman&quot;,&quot;serif&quot;">if  <font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> a=2, b=-5 and c =10, then discriminant = b2-4ac = (-5)2-4*2*10 = 25-80 = -55.

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">Since the discriminant is not 0, hence the roots are distinct. Also since discriminant is lesser than 0, roots are imaginary. Hence as per step 6,

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">x1 <font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> <font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> = p+qi = -b/2a +.((√(discriminant*-1))/2a) i = -(-5)/2*2 + ((√(-55*-1))/22) i = 1.25 + 0.337i

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">x2 <font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> <font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> = p-qi = -b/2a -.((√(discriminant*-1))/2a) i = -(-5)/2*2 - ((√(-55*-1))/22) i = 1.25 - 0.337i

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">Program:<br style="mso-special-character: line-break" /><br style="mso-special-character: line-break" />

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">/*****************************************************************

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> *File                            : 01Quadratic.c
 * Description                : Program to find the roots of a Quadratic Equation
 * Author                                   : Prabodh C P
 * Compiler                               : gcc compiler, Ubuntu 10.04
 * Date                          : 7 September 2010


 * 1) include< stdio.h >
 * 2) include< stdlib.h >
 * 3) include< math.h >

/*****************************************************************

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> *Function                                : main
 * Input parameters       :
 * int argc - no of commamd line arguments
 * char ** argv - vector to store command line argumennts
 * RETURNS                            :
 * 0 on success

int main( int argc, char ** argv ) { float fA,fB,fC,fDesc,fX1,fX2,fRealp,fImagp;

printf("\n*************************************************************"); printf ("\n*\ tPROGRAM TO FIND ROOTS OF A QUADRATIC EQUATION\t *\n"); printf("*************************************************************");

printf ("\ nEnter the coefficients of a,b,c \n"); scanf ("% f%f%f ",& fA ,& fB ,& fC ); if(0 == fA ) {                      printf ("\ nInvalid input not a quadratic equation-try again\n"); exit(0); }

/*COMPUTE THE DESCRIMINANT*/ fDesc = fB  *fB-4* fA  * fC  ;

if(0 == fDesc ) {                      fX1 = fX2 = - fB /(2* fA );

printf ("\ nRoots are equal and the Roots are \n"); printf ("\nRoot1 = %f and Root2 = %f\n",fX1,fX2); }          else if( fDesc > 0) {                      fX1 = (- fB+sqrt ( fDesc ))/(2* fA ); fX2 = (- fB-sqrt ( fDesc ))/(2* fA ); printf ("\ nThe Roots are Real and distinct, they are \n"); printf ("\nRoot1 = %f and Root2 = %f\n",fX1,fX2); }          else {                      fRealp = - fB / (2* fA ); fImagp = sqrt ( fabs ( fDesc ))/(2* fA ); printf ("\ nThe Roots are imaginary and they are\n"); printf ("\nRoot1 = % f+i%f \n", fRealp,fImagp ); printf ("\nRoot2 = % f-i%f \n", fRealp,fImagp ); }

return 0; }<br style="mso-special-character: line-break" /><br style="mso-special-character: line-break" />

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">/***************

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> *         OUTPUT         *

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> ***************/

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> *************************************************************

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> *         PROGRAM TO FIND ROOTS OF A QUADRATIC EQUATION                *

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> *************************************************************

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">Enter the coefficients of a ,b,c

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">1 -4 4

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">Roots are equal and the Roots are

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">Root1 = 2.000000 and Root2 = 2.000000

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> *************************************************************

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> *         PROGRAM TO FIND ROOTS OF A QUADRATIC EQUATION                *

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> *************************************************************

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">Enter the coefficients of a ,b,c

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">1 -5 6

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">The Roots are Real and distinct, they are

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">Root1 = 3.000000 and Root2 = 2.000000

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> *************************************************************

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> *         PROGRAM TO FIND ROOTS OF A QUADRATIC EQUATION                *

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> *************************************************************

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">Enter the coefficients of a ,b,c

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">1 3 3

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">The Roots are imaginary and they are

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">Root1 = -1.500000+i0.866025

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">Root2 = -1.500000-i0.866025

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<span lang="EN-IN" style="mso-fareast-font-family: &quot;Times New Roman&quot;"><font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> 2.<span style="font: 7.0pt &quot;Times New Roman&quot;">      <font face="&quot;Times New Roman&quot;,&quot;serif&quot;">Design, develop and execute a program in C to implement Euclid’s algorithm to find the GCD and LCM of two integers and to output the results along with the given integers.

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">Summary:

In its simplest form, Euclid's algorithm starts with a pair of positive integers, and forms a new pair that consists of the smaller number and the difference between the larger and smaller numbers. The process repeats until the numbers in the pair are equal. That number then is the greatest common divisor of the original pair of integers.

The main principle is that the GCD does not change if the smaller number is subtracted from the larger number. For example, the GCD of 252 and 105 is exactly the GCD of 147 (= 252 − 105) and 105. Since the larger of the two numbers is reduced, repeating this process gives successively smaller numbers, so this repetition will necessarily stop sooner or later — when the numbers are equal (if the process is attempted once more, one of the numbers will become 0).

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">Euclid’s Algorithm can thus be simplified by finding the remainder of the two integers and forms a new pair consisting of the divisor and the remainder.

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">Also to calculate the LCM of any two numbers m and n, following formula can be used if GCD

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">of <font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> the two numbers, GCD( m,n ) is already known.

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">           LCM( m,n ) = (m*n)/GCD( m,n )

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">To illustrate the extension of Euclid's algorithm, consider the computation of gcd  ( 120, 23), which

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">is <font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> shown in the table below. Notice that the quotient in each division is recorded as well

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">alongside <font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> the remainder. In this example, the divisor in the last line (which is equal to 1)

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">indicates <font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> that the gcd is 1; that is, 120 and 23 are coprime (also called relatively prime).

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">Algorithm:

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<span lang="EN-IN" style="mso-fareast-font-family: &quot;Times New Roman&quot;"><font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> 1.<span style="font: 7.0pt &quot;Times New Roman&quot;">      <font face="&quot;Times New Roman&quot;,&quot;serif&quot;">Take the inputs i.e. m and n, the numbers for which GCD and LCM needs to be found.

<span lang="EN-IN" style="mso-fareast-font-family: &quot;Times New Roman&quot;"><font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> 2.<span style="font: 7.0pt &quot;Times New Roman&quot;">      <font face="&quot;Times New Roman&quot;,&quot;serif&quot;">If both m and n are equal to 0, then print “GCD doesn’t exist”. Go to step 9.

<span lang="EN-IN" style="mso-fareast-font-family: &quot;Times New Roman&quot;"><font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> 3.<span style="font: 7.0pt &quot;Times New Roman&quot;">      <font face="&quot;Times New Roman&quot;,&quot;serif&quot;">If n is equal to 0, then go to step 6. Else calculate reminder = m (mod) n.

<span lang="EN-IN" style="mso-fareast-font-family: &quot;Times New Roman&quot;"><font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> 4.<span style="font: 7.0pt &quot;Times New Roman&quot;">      <font face="&quot;Times New Roman&quot;,&quot;serif&quot;">Assign m=n and n = reminder.

<span lang="EN-IN" style="mso-fareast-font-family: &quot;Times New Roman&quot;"><font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> 5.<span style="font: 7.0pt &quot;Times New Roman&quot;">      <font face="&quot;Times New Roman&quot;,&quot;serif&quot;">If new value of n is 0, then go to step 6, else go back to step 3.

<span lang="EN-IN" style="mso-fareast-font-family: &quot;Times New Roman&quot;"><font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> 6.<span style="font: 7.0pt &quot;Times New Roman&quot;">      <font face="&quot;Times New Roman&quot;,&quot;serif&quot;">GCD= m. Print the value of GCD.

<span lang="EN-IN" style="mso-fareast-font-family: &quot;Times New Roman&quot;"><font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> 7.<span style="font: 7.0pt &quot;Times New Roman&quot;">      <font face="&quot;Times New Roman&quot;,&quot;serif&quot;">LCM =  ( Initial value of m * initial value of n) /GCD

<span lang="EN-IN" style="mso-fareast-font-family: &quot;Times New Roman&quot;"><font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> 8.<span style="font: 7.0pt &quot;Times New Roman&quot;">      <font face="&quot;Times New Roman&quot;,&quot;serif&quot;">STOP

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">Example:

<span lang="EN-IN" style="mso-fareast-font-family: &quot;Times New Roman&quot;"><font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> a)<span style="font: 7.0pt &quot;Times New Roman&quot;">      <font face="&quot;Times New Roman&quot;,&quot;serif&quot;">If m = 10, n = 15

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">Hence,

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">GCD = m = 5.

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">LCM = (Initial m *Initial n)/GCD = (10*15)/5 = 30.

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">Program:

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">/*****************************************************************

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> *File                            : 02GcdLcm.c

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> *Description                : Program to find the GCD & LCM of two numbers

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> *Author                                   : Prabodh C P

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> *Compiler                               : gcc compiler, Ubuntu 10.04

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> *Date                          : 7 September 2010

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> *****************************************************************/

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> #include< stdio.h >

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> #include< stdlib.h >

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">/*****************************************************************

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> *Function                                : main

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> *Input parameters       :

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> *          int  argc - no of commamd line arguments

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> *         char ** argv - vector to store command line argumennts

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> *RETURNS                            :

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> *         0 on success

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> *****************************************************************/

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">int  <font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> main( int argc, char ** argv )

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">{

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">            int  iX1,iX2,iY1,iY2,iRem,iGcd,iLcm; printf("\n*********************************************************");

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">            printf  ( "\n*\ tPROGRAM TO FIND GCD & LCM OF TWO NUMBERS\t*\n");

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">printf( <font face="&quot;Times New Roman&quot;,&quot;serif&quot;">"*********************************************************");

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">            printf  ( "\ nEnter two numbers\n");

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">            scanf  ( "%d%d",&iX1,&iX2);

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">           if( 0 == iX1 && 0 == iX2)

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">           {

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">                        printf  ( "\ nGCD doesn't  exist\n");

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">                       exit( 0);

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">           }

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">           else      /*APPLY EUCLID'S ALGORITHM*/

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">           {

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">                       iY1 = iX1;

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">                       iY2 = iX2;

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">                      while( iY2!=0)

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">                       {

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">                                    iRem  = iY1%iY2;

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">                                   iY1 = iY2;

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">                                   iY2 = iRem  ;

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">                       }

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">                        iGcd  = iY1;

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">                        iLcm  = (iX1*iX2)/ iGcd  ;

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">                        printf  ( "\n LCM of %d and %d is= %d\n",iX1,iX2,iLcm);

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">           }

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">           return 0;

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">}<br style="mso-special-character: line-break" /><br style="mso-special-character: line-break" />

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">/***************

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> *         OUTPUT         *

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> ***************/

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> *********************************************************

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> *         PROGRAM TO FIND GCD & LCM OF TWO NUMBERS           *

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> *********************************************************

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">Enter two numbers

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">0 0

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">GCD doesn't exist

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> *********************************************************

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> *         PROGRAM TO FIND GCD & LCM OF TWO NUMBERS           *

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> *********************************************************

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">Enter two numbers

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">64 48

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> GCD of 64 and 48 is= 16

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> LCM of 64 and 48 is= 192

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> *********************************************************

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> *         PROGRAM TO FIND GCD & LCM OF TWO NUMBERS           *

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> *********************************************************

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">Enter two numbers

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">5 0

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> GCD of 5 and 0 is= 5

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> LCM of 5 and 0 is= 0

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<span lang="EN-IN" style="mso-fareast-font-family: &quot;Times New Roman&quot;"><font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> 3.<span style="font: 7.0pt &quot;Times New Roman&quot;">      <font face="&quot;Times New Roman&quot;,&quot;serif&quot;">Design, develop and execute a program in C to reverse a given four digit integer number and check whether it is a palindrome or not. Output the given number with suitable message.<br style="mso-special-character: line-break" /><br style="mso-special-character: line-break" />

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">Summary:

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">Palindrome is a number, word, phrase, or sequence that reads the same backward as forward, e.g., “madam” or “ malayalam ” or 1221 or 10301.

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">Algorithm:

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<span lang="EN-IN" style="mso-fareast-font-family: &quot;Times New Roman&quot;"><font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> 1.<span style="font: 7.0pt &quot;Times New Roman&quot;">      <font face="&quot;Times New Roman&quot;,&quot;serif&quot;">Get the input i.e. num, the 4 digit number which needs to be checked for being a palindrome

<span lang="EN-IN" style="mso-fareast-font-family: &quot;Times New Roman&quot;"><font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> 2.<span style="font: 7.0pt &quot;Times New Roman&quot;">      <font face="&quot;Times New Roman&quot;,&quot;serif&quot;">Initialize rev=0.

<span lang="EN-IN" style="mso-fareast-font-family: &quot;Times New Roman&quot;"><font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> 3.<span style="font: 7.0pt &quot;Times New Roman&quot;">      <font face="&quot;Times New Roman&quot;,&quot;serif&quot;">Calculate the remainder and quotient when num is divided by 10. Rem = num  ( mod) 10 and quo = num /10.

<span lang="EN-IN" style="mso-fareast-font-family: &quot;Times New Roman&quot;"><font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> 4.<span style="font: 7.0pt &quot;Times New Roman&quot;">      <font face="&quot;Times New Roman&quot;,&quot;serif&quot;">Assign num = quo and rev = (rev*10)+rem

<span lang="EN-IN" style="mso-fareast-font-family: &quot;Times New Roman&quot;"><font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> 5.<span style="font: 7.0pt &quot;Times New Roman&quot;">      <font face="&quot;Times New Roman&quot;,&quot;serif&quot;">If num is equal to 0, go to step 6, else go back to 3.

<span lang="EN-IN" style="mso-fareast-font-family: &quot;Times New Roman&quot;"><font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> 6.<span style="font: 7.0pt &quot;Times New Roman&quot;">      <font face="&quot;Times New Roman&quot;,&quot;serif&quot;">Compare initial num and rev. If they are equal, then print initial num is a palindrome. Else print that initial num is not a palindrome.

<span lang="EN-IN" style="mso-fareast-font-family: &quot;Times New Roman&quot;"><font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> 7.<span style="font: 7.0pt &quot;Times New Roman&quot;">      <font face="&quot;Times New Roman&quot;,&quot;serif&quot;">STOP

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">Program:

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">/*****************************************************************

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> *File                            : 03Palindrome.c

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> *Description                : Program to check whether the given integer is a Palindrome or not

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> *Author                                   : Prabodh C P

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> *Compiler                               : gcc compiler, Ubuntu 10.04

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> *Date                          : 7 September 2010

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> *****************************************************************/

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> #include< stdio.h >

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> #include< stdlib.h >

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">/*****************************************************************

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> *Function                                : main

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> *Input parameters       :

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> *          int  argc - no of commamd line arguments

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> *         char ** argv - vector to store command line argumennts

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> *RETURNS                            :

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> *         0 on success

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> *****************************************************************/

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">int  <font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> main( int argc, char ** argv )

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">{

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">            int  iNum,iRev = 0,iTemp,iRem;

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">            printf  ( "\n*\ tPROGRAM TO CHECK WHETHER AN INTEGER IS A PALINDROME OR NOT\t *\n");

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">           printf( "**************************************************************************");

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">            printf  ( "\ nEnter a number\n");

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">            scanf  ( "%d",& iNum );

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">            iTemp  = iNum  ;

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">           while( iNum  !=0)

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">           {

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">                        iRem  = iNum % 10;

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">                        iRev  = iRev * 10 + iRem  ;

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">                        iNum  = iNum /10;

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">           }

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">            printf  ( "\ nReverse is %d", iRev );

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">           if( iRev == iTemp )

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">                        printf  ( "\ nNumber %d is a palindrome\n", iTemp );

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">           else

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">                        printf  ( "\ nNumber %d is not a palindrome\n", iTemp );

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">           return 0;

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">}

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">/***************

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> *         OUTPUT         *

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> ***************/

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> ******************************************************************

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> *         PROGRAM TO CHECK WHETHER AN INTEGER IS A PALINDROME OR NOT     *

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> ******************************************************************

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">Enter a number

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">7667

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">Reverse is 7667

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">Number 7667 is a palindrome

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> ******************************************************************

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> *         PROGRAM TO CHECK WHETHER AN INTEGER IS A PALINDROME OR NOT     *

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> ******************************************************************

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">Enter a number

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">1234

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">Reverse is 4321

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">Number 1234 is not a palindrome

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"><font size="11.0pt">4) Design, develop and execute a program in C to evaluate the given polynomial f(x) = a4x4 + a3x3 + a2x2 + a1x + a0 for given value of x and the coefficients using Horner’s method.

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"><font size="13.0pt">Summary:

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">Horner's method of polynomial evaluation is described below

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">The expression is broken down in the following way

 <font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> 

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">f( <font face="&quot;Times New Roman&quot;,&quot;serif&quot;">x) =  a4x <font face="&quot;Times New Roman&quot;,&quot;serif&quot;"><font size="10.5pt">4 <font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> +  a3x <font face="&quot;Times New Roman&quot;,&quot;serif&quot;"><font size="10.5pt">3 <font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> + a2x <font face="&quot;Times New Roman&quot;,&quot;serif&quot;"><font size="10.5pt">2 <font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> + a1x + a0

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">f( <font face="&quot;Times New Roman&quot;,&quot;serif&quot;">x) =  x ( a4x <font face="&quot;Times New Roman&quot;,&quot;serif&quot;"><font size="10.5pt">3 <font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> +  a3x <font face="&quot;Times New Roman&quot;,&quot;serif&quot;"><font size="10.5pt">2 <font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> + a2x + a1 ) + a0

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">f( <font face="&quot;Times New Roman&quot;,&quot;serif&quot;">x) =  x (  x(   a4x <font face="&quot;Times New Roman&quot;,&quot;serif&quot;"><font size="10.5pt">2 <font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> +  a3x2 + a2 )  + a1 ) + a0

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">f( <font face="&quot;Times New Roman&quot;,&quot;serif&quot;">x) =  x (  x(   x ( a4x +  a3 ) + a2 )  + a1 ) + a0

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">f(x) = x (  x(   x (   x (  a4 )  +  a3 ) + a2 )  + a1 ) + a0

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"><font size="13.0pt">Example:

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">Input values:

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">x=6

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">a0 =5, a 1 =4, a 2 =3, a 3 =2, a 4 =1

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">sum <font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> =    a4 * x                        →  1 * 6                     → 6

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">sum <font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> =    ( sum + a3 )   * x         →  ( 6 + 2 ) * 6          → 48

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">sum <font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> =    ( sum + a2 )   * x        →  ( 48  + 3 ) * 6        →  306

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">sum <font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> =    ( sum + a1 )   * x        →  ( 306  + 4 ) *6       →  1860

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">Algorithm:

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">Step 1 :  Start

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">Step 2  :  Input the degree and value of x

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">Step 3  :  Input Coefficients, upper limit is provided  by the value of degree

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">Step 4   : i   =  degree,  sum =0

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">Step 5   : sum = ( sum + ai ) * x

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">Step 6  :  decrement i by 1

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">Step 6   : if ( i   > 0 ) goto step 5

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">Step 7 : add a0 to the final sum

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">Step 8 : display sum

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">Step 9   : Stop

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"><font size="13.0pt">Program:

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"><font size="13.0pt">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">/*****************************************************************

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> *File                            : 04Horner.c

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> *Description                : Program to implement Horners method for Polynomial evaluation

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> *Author                                   : Prabodh C P

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> *Compiler                               : gcc compiler, Ubuntu 10.04

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> *Date                          : 7 September 2010

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> *****************************************************************/

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> #include< stdio.h >

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> #include< stdlib.h >

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> #include< math.h >

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">/*****************************************************************

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> *Function        :          main

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> *Input parameters:     no parameters

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> *RETURNS    :           0 on success

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> *****************************************************************/

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">int  <font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> main(void)

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">{

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">            int  iDeg,i,iaArr [10];

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">           float fX,fSum  =0;

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">           printf( "\n*********************************************************************");

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">            printf  ( "\n*\ tPROGRAM TO EVALUATE A POLYNOMIAL USING HORNERS METHOD\t     *\n");

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">           printf( "*********************************************************************");

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">            printf  ( "\ nEnter the degree of the polynomial and value of x\n");

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">            scanf  ( "% d%f ",& iDeg ,& fX );

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">            printf  ( "\ nEnter the coefficients in descending order of degree\n");

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">           for( i  =0;i<= iDeg;i ++)

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">           {

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">                        scanf  ( "%d",& iaArr [ i ]);

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">           }

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">           for( i  =0;i< iDeg;i ++)

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">           {

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">                        fSum   =( fSum+iaArr [ i ])* fX  ;

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">           }

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">            fSum  = fSum + iaArr [ iDeg ];

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">            printf  ( "\ nValue of polynomial after evaluation=%g\n", fSum );

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">           return 0;

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">}

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">/***************

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> *         OUTPUT         *

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> ***************/

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> ****************************************************************

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> *         PROGRAM TO EVALUATE A POLYNOMIAL USING HORNERS METHOD     *

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> ****************************************************************

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">Enter the degree of the polynomial and value of x

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">5

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">2

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">Enter the coefficients in reverse order

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">6 5 4 3 2 1

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">Value of polynomial after evaluation=120.000000

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> ****************************************************************

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> *         PROGRAM TO EVALUATE A POLYNOMIAL USING HORNERS METHOD     *

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> ****************************************************************

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">Enter the degree of the polynomial and value of x

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">4 1

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">Enter the coefficients in reverse order

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">1 2 3 4 5

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">Value of polynomial after evaluation=15.000000

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<span lang="EN-IN" style="mso-fareast-font-family: &quot;Times New Roman&quot;"><font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> 5.<span style="font: 7.0pt &quot;Times New Roman&quot;">      <font face="&quot;Times New Roman&quot;,&quot;serif&quot;">Design, develop and execute a program in C to copy its input to its output, replacing each string of one or more blanks by a single blank.

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">Summary:

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">The program introduces concept of Character comparision and also white space characters like ‘\t’ and null characters like ‘\0’ To find and replace all multiple blanks, with a single blank in the string, we will start from second character as current character in the input string and compare it with the previous character and if only both are not spaces, then the current character will stored in the destination string. We will continue this till we reach the end of the input string which is denoted by null character, ‘\0’.

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">Algorithm:

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<span lang="EN-IN" style="mso-fareast-font-family: &quot;Times New Roman&quot;"><font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> 1)<span style="font: 7.0pt &quot;Times New Roman&quot;">      <font face="&quot;Times New Roman&quot;,&quot;serif&quot;">Take the input, acSStr, i.e. array of characters including multiple spaces and tabs.

<span lang="EN-IN" style="mso-fareast-font-family: &quot;Times New Roman&quot;"><font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> 2)<span style="font: 7.0pt &quot;Times New Roman&quot;">      <font face="&quot;Times New Roman&quot;,&quot;serif&quot;">Initialize an destination array, acDStr, which will hold the value of results

<span lang="EN-IN" style="mso-fareast-font-family: &quot;Times New Roman&quot;"><font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> 3)<span style="font: 7.0pt &quot;Times New Roman&quot;">      <font face="&quot;Times New Roman&quot;,&quot;serif&quot;">Initialize variable cPrevChar as the first element of the input array and cCurrentChar as the second element of the input array.

<span lang="EN-IN" style="mso-fareast-font-family: &quot;Times New Roman&quot;"><font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> 4)<span style="font: 7.0pt &quot;Times New Roman&quot;">      <font face="&quot;Times New Roman&quot;,&quot;serif&quot;">Check if cPrevChar is a tab, ‘\t’, if so, add a space to the Destination array, acDStr and assign cPrevChar to a space, “ “.

<span lang="EN-IN" style="mso-fareast-font-family: &quot;Times New Roman&quot;"><font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> 5)<span style="font: 7.0pt &quot;Times New Roman&quot;">      <font face="&quot;Times New Roman&quot;,&quot;serif&quot;">If cCurrentChar is equal to null character, ‘\0’, then go to step 10.

<span lang="EN-IN" style="mso-fareast-font-family: &quot;Times New Roman&quot;"><font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> 6)<span style="font: 7.0pt &quot;Times New Roman&quot;">       <font face="&quot;Times New Roman&quot;,&quot;serif&quot;">If both  <font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> aPrevChar and cCurrentChar are white spaces, then go to step 9.

<span lang="EN-IN" style="mso-fareast-font-family: &quot;Times New Roman&quot;"><font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> 7)<span style="font: 7.0pt &quot;Times New Roman&quot;">      <font face="&quot;Times New Roman&quot;,&quot;serif&quot;">If cCurrentChar is a tab, then assign it to a space.

<span lang="EN-IN" style="mso-fareast-font-family: &quot;Times New Roman&quot;"><font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> 8)<span style="font: 7.0pt &quot;Times New Roman&quot;">      <font face="&quot;Times New Roman&quot;,&quot;serif&quot;">Add cCurrentChar to destination array, acDStr.

<span lang="EN-IN" style="mso-fareast-font-family: &quot;Times New Roman&quot;"><font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> 9)<span style="font: 7.0pt &quot;Times New Roman&quot;">      <font face="&quot;Times New Roman&quot;,&quot;serif&quot;">Assign cPrevChar to cCurrentChar and assign cCurrentChar to the next element in the input String, acSStr . Go to step 5.

<span lang="EN-IN" style="mso-fareast-font-family: &quot;Times New Roman&quot;"><font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> 10)<span style="font: 7.0pt &quot;Times New Roman&quot;">  <font face="&quot;Times New Roman&quot;,&quot;serif&quot;">Assign a null character, ‘\0’ to the destination string, acDStr.

<span lang="EN-IN" style="mso-fareast-font-family: &quot;Times New Roman&quot;"><font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> 11)<span style="font: 7.0pt &quot;Times New Roman&quot;">  <font face="&quot;Times New Roman&quot;,&quot;serif&quot;">Print the destination string, acDStr.

<span lang="EN-IN" style="mso-fareast-font-family: &quot;Times New Roman&quot;"><font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> 12)<span style="font: 7.0pt &quot;Times New Roman&quot;">  <font face="&quot;Times New Roman&quot;,&quot;serif&quot;">STOP.

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">/*****************************************************************

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> *File                            : 05RemSpace.c

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> *Description                : Program to replace multiple whitespaces with a single space

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> *Author                                   : Prabodh C P

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> *Compiler                               : gcc compiler, Ubuntu 10.04

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> *Date                          : 7 September 2010

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> *****************************************************************/

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> #include< stdio.h >

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> #include< stdlib.h >

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">/*****************************************************************

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> *Function                                : main

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> *Input parameters       :

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> *          int  argc - no of commamd line arguments

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> *         char ** argv - vector to store command line argumennts

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> *RETURNS                            :

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">           0 on success

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> *****************************************************************/

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">int  <font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> main( int argc, char ** argv )

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">{

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">           char acSStr [100], acDStr [100];

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">            int  i,j  =0;

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">           char cPrevChar,cCurChar  ;

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">            int  iPrevSpace,iCurSpace  ;

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">printf( <font face="&quot;Times New Roman&quot;,&quot;serif&quot;">"\n*************************************************************************");

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">            printf  ( "\n*\ tPROGRAM TO REPLACE MULTIPLE WHTESPACES WITH A SINGLE BLANK\t*\n");

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">           printf( "*************************************************************************");

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">            printf  ( "\ nEnter a Sentence\n");

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">           gets( acSStr );

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">            cPrevChar  = acSStr [0];

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">            cCurChar  = acSStr [1];

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">           /*IF FIRST CHARACTER IS A TAB REDUCE IT TO A SINGLE SPACE*/

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">           if( cPrevChar == '\t')

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">                        cPrevChar  = ' ';

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">            acDStr  [ j++] = cPrevChar  ;

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">           // for( i = 1; (*( acSStr+i )); i ++)

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">           for( i = 1; acSStr [ i ] != '\0'; i ++)

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">           {

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">                        iPrevSpace  = 0;

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">                        iCurSpace  = 0;

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">                       /*CHECK WHETHER PREVIOUS CHARECTER WAS A WHITESPACE*/

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">                       if( cPrevChar == ' ' || cPrevChar == '\t')

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">                                    iPrevSpace  = 1;

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">                       /*CHECK WHETHER CURRENT CHARECTER WAS A WHITESPACE*/

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">                       if( cCurChar == ' ' || cCurChar == '\t')

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">                                    iCurSpace  = 1;

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">                       /*CHECK WHETHER BOTH PREVCHAR & CURCHAR ARE NOT SPACES*/

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">                       if(  !( iPrevSpace && iCurSpace ))

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">                       {

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">                                   /*THEN COPY CURCHAR INTO DESTINATION STRING*/

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">                                   /* IF CURCHAR IS A TAB REDUCE IT TO A SPACE*/

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">                                   if( cCurChar == '\t')

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">                                                cCurChar  = ' ';

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">                                    acDStr  [ j++] = cCurChar  ;

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">                       }

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">                        cPrevChar  = cCurChar  ;

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">                        cCurChar  = acSStr [i+1];

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">           }

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">           /*PLACE A NULL TERMINATOR AT END OF STRING*/

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">            acDStr  [ j] = '\0';

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">            printf  ( "\ nThe String without spaces is\n");

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">           puts( acDStr );

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">           return 0;

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">} /***************

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> *         OUTPUT         *

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> ***************/

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> *****************************************************************

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> *         PROGRAM TO REPLACE MULTIPLE WHTESPACES WITH A SINGLE BLANK     *

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> *****************************************************************

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">Enter a Sentence

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">I like                          programming     C.

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">The String without spaces is

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">I like programming C.

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> *****************************************************************

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> *         PROGRAM TO REPLACE MULTIPLE WHTESPACES WITH A SINGLE BLANK     *

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> *****************************************************************

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">Enter a Sentence

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">                       I          am                  an Indian

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">The String without spaces is

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> I am an Indian

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">6. Design, develop and execute a program in C to input N integer numbers in ascending order into a single dimension array, and then to perform a binary search for a given key integer number and report success or failure in the form of a suitable message.

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">Summary:

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">Binary search or half-interval search algorithm finds the position of a specified input value (the search "key") within an array sorted by key value. In each step, the algorithm compares the search key value with the key value of the middle element of the array. If the keys match, then a matching element has been found and its index, or position, is returned. Otherwise, if the search key is less than the middle element's key, then the algorithm repeats its action on the sub-array to the left of the middle element or, if the search key is greater, on the sub-array to the right. If the remaining array to be searched is empty, then the key cannot be found in the array and a special "not found" indication is returned.

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">Example: <font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> Array = 1 3 4 6 8 9 11 Key = 4

Iteration1: Find the mid element of Array, its 6 Compare key to 6. It's smaller. Repeat with Array = 1 3 4. Iteration2: Find the mid element, its 3 Compare key to 3. It's bigger. Repeat with Array = 4. Iteration3: Find mid element, its 4 Compare key to 4. It's equal. We're done, we found key.

In each iteration the length of the list we are looking in gets cut in half. Therefore, the total number of iterations cannot be greater than logN. <br style="mso-special-character: line-break" /><br style="mso-special-character: line-break" />

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">Algorithm : <font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">Step 1: Start Step 2: Input Length of array Step 3: Input the array elements on by one in Non-descending order Step 4: Input Key element to search Step 5: if length of array < 1 goto step 12 Step 6: Find the mid element of the array Step 7: If mid element matches the key, goto step 11 Step 8: If mid element > key, goto step 9 else goto step 10 Step 9: Set the end of the array as the element before mid element. Go to step 5 Step 10: Set the beginning of the array as the element after the mid element. Go to step 5 Step 11: Display successfully found key, goto step 13 Step 12: Display unsuccessful in finding the key Step 13: Stop<br style="mso-special-character: line-break" /><br style="mso-special-character: line-break" />

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">Program:

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">/*****************************************************************

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> *File                            : 06BinarySearch.c

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> *Description                : Program to implement binary search

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> *Author                                   : Prabodh C P

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> *Compiler                               : gcc compiler, Ubuntu 10.04

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> *Date                          : 7 September 2010

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> *****************************************************************/

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> #include< stdio.h >

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> #include< stdlib.h >

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">/*****************************************************************

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> *Function                                : main

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> *Input parameters       :

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> *          int  argc - no of commamd line arguments

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> *         char ** argv - vector to store command line argumennts

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> *RETURNS                            :

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">           0 on success

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> *****************************************************************/

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">int  <font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> main( int argc, char ** argv )

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">{

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">            int  iNum, i , iFound , iaArr [10], iKey , iPos , iLow , iHigh , iMid  ;

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">            printf  ( "\n**************************************************");

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">            printf  ( "\n*\ tPROGRAM TO IMPLEMENT BINARY SEARCH\t *\n");

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">            printf  ( "**************************************************");

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">            printf  ( "\ nEnter no of elements\n");

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">            scanf  ( "%d",& iNum );

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">            printf  ( "\ nEnter the elements in ascending order\n");

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">           for( i  =0;i< iNum;i ++)

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">                        scanf  ( "%d",& iaArr [ i ]);

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">            printf  ( "\ nEnter the Key element\n");

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">            scanf  ( "%d",& iKey );

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">            iFound  = 0;

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">            iLow  = 0;

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">            iHigh  = iNum-1;

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">           while( iLow <= iHigh )

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">           {

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">                        iMid  = ( iLow + iHigh )/2;

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">                       if( iKey == iaArr [ iMid ])          /*KEY ELEMENT FOUND*/

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">                       {

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">                                    iPos  = iMid  ;

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">                                    iFound  = 1;

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">                                   break  ;

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">                       }

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">                       else if( iKey < iaArr [ iMid ])      /*KEY ELEMENT IS IN 1ST HALF*/

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">                                    iHigh  = iMid - 1;

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">                       else      /*KEY ELEMENT IS IN 2ND HALF*/

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">                                    iLow  = iMid +1;

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">           }

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">           if( iFound )

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">                        printf  ( "\ nKey element %d found at position %d\n",iKey,iPos+1);

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">           else

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">                        printf  ( "\ nKey element not found\n");

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">           return 0;

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">}

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">/***************

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> *         OUTPUT         *

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> ***************/

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> **************************************************

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> *         PROGRAM TO IMPLEMENT BINARY SEARCH           *

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> **************************************************

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">Enter no of elements

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">5

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">Enter the elements in ascending order

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">1 3 5 7 9

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">Enter the Key element

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">7

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">Key element 7 found at position 4

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> **************************************************

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> *         PROGRAM TO IMPLEMENT BINARY SEARCH           *

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;"> **************************************************

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">Enter no of elements

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">4

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">Enter the elements in ascending order

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">2 4 6 8

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">Enter the Key element

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">5

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">

<font face="&quot;Times New Roman&quot;,&quot;serif&quot;">Key element not found