.model small
.data
result dw ?
.code
main proc
mov ax,@data
mov ds,ax
mov cx,20
mov dx,0
mov bx,3
mov ax,2
here:mul bx
add result,ax
div bx
add ax,2
add bx,2
loop here
mov ax,4c00h
int 21h
main endp
end
.data
result dw ?
.code
main proc
mov ax,@data
mov ds,ax
mov cx,20
mov dx,0
mov bx,3
mov ax,2
here:mul bx
add result,ax
div bx
add ax,2
add bx,2
loop here
mov ax,4c00h
int 21h
main endp
end
In C, the code is
ReplyDelete/*add 2*3 + 4*5 + 6*7 + ...... upto 20 terms */
#include
#include
void main()
{
int i,j,c,sum=0;
for(i=2,j=3,c=1;c<=20;i=i+2,j=j+2,c++)
{
sum+=i*j;
}
printf("\nTotal sum is %d",sum);
getch();
}