August 2017

## EEE 306 Lab 6 : Bracketing methods for finding roots

Write a program to find root of an equation in the form ax^2+bx+c, where a,b,c, will be taken as input. You have to take input the number of iteration and the termination criterion.

Use bisection method to find the root where the upper limit and lower limit will be taken as input.

Write a program to find root of an equation in the form ax^2+bx+c, where a,b,c, will be taken as input. You have to take input the number of iteration and the termination criterion.

Use False Position method to find the root where the upper limit and lower limit will be taken as input.

## CSE 506 Lab 6

Practise #1 (Example 6.4)
If AX contains a negative number, put -1 In BX; if AX contains 0, put O In BX; if AX contains a positive number, put 1 In BX.·

```mov ax,0FFFBh
CMP AX,0
JL NEGATIVE
JE ZERO
JG POSITIVE
NEGATIVE:
MOV BX,-1
JMP END_CASE
ZERO:
MOV BX,0
JMP END_CASEPOSITIVE:
MOV BX,1
JMP END_CASE
END_CASE:
MOV AX,4CH
INT 21h
MAIN ENDP
END MAIN```

Practise #2 (example 6.5)
If AL contains I or 3, display “o”; if AL contains 2 or 4, Display “e”.

```CMP AL,1
JE ODD
CMP AL,3
JE ODD
CMP AL,2
JE EVEN
CMP AL,4
JE EVEN
ODD:
MOV DL,'o'
JMP DISPLAY
EVEN:
MOV DL,'e'
JMP DISPLAY:
DISPLAY:
MOV AH,2
INT 21h```

Practise #3 (example 6.6)
Read a character and if it is uppercase display it

``` MOV AH,1
INT 21H
CMP AL,'A'
JNGE NOT
CMP AL,'Z'
JNLE NOT
MOV DL,AL
MOV AH,2
INT 21h
NOT:```

Practise #4 (example 6.7)
Read a character. If it’s “y” or “Y”, display it; otherwise, terminate the program.

```MOV AH,1
INT 21H
CMP AL,'y'
JE THEN
CMP AL,'Y'
JE THEN
JMP ELSE
THEN:
MOV AH,2
MOV DL,AL
INT 21H
JMP EXIT
ELSE:
JMP EXIT
EXIT:```

Practise #5 (Example 6.9)
Write some code to count the number of characters In a input line.

```MOV DX,0
MOV AH,l
INT 21H
WHILE:
CMP ·AL, OOH ;CR?
JE END_WHILE ;yes, exit
INC DX ;not CR, increment count
JMP WHILE ;loop back;
END_WHILE:```

Problem #1
Write a program to display a “?”, read two capital letters, and dis-play them on the next line In alphabetical order.

Practise #6 (Example 6.10)

```MOV AH,l
repeat:
INT 21H
CMP AL,' '
JNE REPEAT```

Marut section 6.5

Submit Assignment 4[Lab 6 and 7] through this link

## EEE 306 Lab 5 : Taylor series sine and cosine

Write a program to find an estimate of any value of cos(x). You should take input the value of x in degree, the maximum number of iteration, and the minimum error requirement

Sample code

```#include<stdio.h>
#include<math.h>
int fact(int n)
{
if (n==1){return 1;}
return n*fact(n-1);
}
int main()
{
int i,j, iter, sign=1;
double x, es,ea, previous=1, approx=1, curr_approx;
scanf("%lf", &x);
x=(x/180)*3.141592654;
//printf("%lf\n", x);
scanf("%d", &iter);
scanf("%lf", &es);
for (i=1;i<iter;i++)
{
j=i*2;
curr_approx=(pow(x,j)/(fact(j)));
if (sign%2==1)
{
approx=approx-curr_approx;
}
else {approx=approx+curr_approx;}

ea=fabs(((approx-previous)/approx)*100);
previous=approx;
sign++;
printf("\n %lf\t %lf", approx, ea);
if (ea<es) break;

}

printf("\n%lf", approx);
}```

Write a program to find an estimate of any value of sin(x). You should take input the value of x in degree, the maximum number of iteration, and the minimum error requirement

Sample code

```#include<stdio.h>
#include<math.h>
int fact(int n)
{
if (n==1){return 1;}
return n*fact(n-1);
}
int main()
{
int i,j, iter, sign=0;
double x, es,ea, previous=0, approx=0, curr_approx;
scanf("%lf", &x);
x=(x/180)*3.141592654;
//printf("%lf\n", x);
scanf("%d", &iter);
scanf("%lf", &es);
for (i=1;i<iter;i++)
{
j=(i*2)-1;
curr_approx=(pow(x,j)/(fact(j)));
if (sign%2==1)
{
approx=approx-curr_approx;
}
else {approx=approx+curr_approx;}

ea=fabs(((approx-previous)/approx)*100);
previous=approx;
sign++;
printf("\n %lf\t %lf", approx, ea);
if (ea<es) break;

}

printf("\n%lf", approx);
}```

## Assignment

There is no assignment for this lab.

## CSE 506 Lab 5

Practise #1 (Eg 6.1)

Write a code to find the greater signed number of the numbers stored in AX and BX

```ABC:
mov ah, 1
int 21h
mov bl, al

int 21h
mov bh, al

cmp bl, bh
jG point1
jl point2

point1:
mov ah, 2
mov dl, '>'
int 21h
jmp ABC

point2:
mov ah, 2
mov dl, '<'
int 21h

jmp ABC```

Practise #2
Print 80 star using condition

```mov cx, 80
point1:
mov ah, 2
mov dl, '*'
int 21h
dec cx
jnz point1```

Problem #1
Print 10*10 box with star (*) without using string and using conditions

Practise #3 (eg 6.2)
Replace a number with absolute number

```mov ax,0FFFBh

cmp ax, 0
jnl point1
neg ax

point1:```

Practise #4 (eg 6.3)
Suppose AL and BL contain extended ASCII characters. Display the one that comes first in the character sequence.

```MOV AH,2
CMP AL,BL
JNBE NOT_AL
MOV DL,AL
JMP DISPLAY
NOT_AL:
MOV DL,BL
JMP DISPLAY
DISPLAY:
INT 21h```

## EEE 306 Lab 4 : More Fun at C

P.S. This lab is not related to numerical analysis. This lab is about basic C and is on students request.

### Problem #1

Printing primes in a range

Fizz buzz

### Problem #3

Smaller larger than average

CGPA calculator