Monday, August 29

Determining the last and the first letter to occur in alphabetical order

.model small
.code
org 100h
jmp main
    parlist label byte
    maxlen db 30
    actlen db ?
    kbdata db 30 dup(' ')
   
    intro db 'Enter string:  ','$'
    first db 'First:  ','$'
    last db 'Last:  ','$'
input:
    mov ah,0ah
    lea dx,parlist
    int  21h
    ret
printing:
    mov ah,09h
    int 21h
    ret
clr_scr:
    mov ax,0600h
    mov bh,07h
    mov cx,0000h
    mov dx,184fh
    int 10h
    ret
set_cur:
    mov ah,02h
    mov bh,00h
    int 10h
    ret

main proc near
    call clr_scr
    mov dx,0000h
    call set_cur
    lea dx,intro
    call printing
    mov dx,0305h
    call set_cur
    call input
    mov dx,0505h
    call set_cur
    mov bl,actlen
    mov bh,00h
    mov al,61h
    mov cl,7ah
    mov si,00h
    mov di,00h
    lea dx,first
    call printing
    call compare1
    mov dx,0605h
        call set_cur
    lea dx,last
    call printing
    call compare2
    main endp
    end main

compare1:
mov ch,kbdata[si]
cmp ch,cl
jb below
inc si
cmp si,bx
je print1
jmp compare1

below:
mov cl,ch
mov si,00h
jmp compare1

compare2:
mov ch,kbdata[di]
cmp ch,al
ja above
inc di
cmp di,bx
je print2
jmp compare2

above:
mov al,ch
mov di,00h
jmp compare2

print1:
mov ah,02h
mov dl,cl
int 21h
ret

print2:
mov ah,02h
mov dl,al
int 21h
ret


/*Screen Shot*/


Tuesday, August 23

Capitalizing The Small Letters In An Input string


.model small
.code
org 100h
jmp main
parlist label byte
maxlen db 40
actlen db ?
kbdata db 40 dup(' ')

labelinput db 'Enter String: ','$'
con db 40 dup(' ')

input:
    mov ah,0ah
    lea dx,parlist
    int  21h
    ret
printing:
    mov ah,09h
    int 21h
    ret
clr_scr:
    mov ax,0600h
    mov bh,07h
    mov cx,0000h
    mov dx,184fh
    int 10h
    ret
set_cur:
    mov ah,02h
    mov bh,00h
    int 10h
    ret

main proc near
    call clr_scr
    mov dx,0000h
    call set_cur
    lea dx,labelinput
    call printing
    mov dx,0305h
    call set_cur
call input
mov dx,0505h
call set_cur
mov bl,actlen
mov bh,00h
mov si,00h
mov di,00h
call process
mov con[di],00100100b
lea dx,con
call printing

mov ah, 4ch
int 21h

main endp
end main
return:
ret
space:
mov con[di],00100000b
inc si
inc di
jmp process
process:
cmp si,bx
je return
mov dl,kbdata[si]
cmp dl,00100000b
je space
cmp dl,60
ja lowerkeys
jb upperkeys
upperkeys:
mov con[di],dl
inc di
inc si
jmp process
lowerkeys:
and dl,11011111b
mov con[di],dl
inc si
inc di
jmp process

/*Screen Shot*/


Monday, August 22

Multiplication Table


#include <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
    long Length,Width,x,y;
    cout<<"\nEnter Length(Horizontal Range_Columns): ";
    cin>>Length;
    cout<<"\nEnter Width(Vertical Range_Rows):       ";
    cin>>Width;
    cout<<"\nTable of Multiplication:\n\n";
    for(x=1;x<=Width;x++){
                          for(y=1;y<=Length;y++){
                                                 cout<<x*y<<" ";
                                                 }
                                                 cout<<"\n";
                                                 }
    cout<<"\n\n\n";
/*Note: Table is not well organized, specially when dealing with great numbers.*/                        
    system("PAUSE");
    return EXIT_SUCCESS;
}

/*Program Preview*/


Prime Factorization


#include <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
    long num,x,qoutient;
    cout<<"Enter Number: ";
    cin>>num;
    cout<<"\n\tPrime Factors of "<<num<<" is : ";
    for(x=num-1;x>0;x--){
                         qoutient=num/x;
                         if(num%x==0){cout<<"  "<<qoutient;num=x;}
                         }
    cout<<"\n\n\n";
    system("PAUSE");
    return EXIT_SUCCESS;
}


/*Program Preview*/


Factorial


#include <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{  
    long num,x,product=1;
    cout<<"Enter Number : ";
    cin>>num;
    for(x=1;x<=num;x++){
                        product*=x;
                        }
    cout<<"\n\n\tFactorial of "<<num<<" is : "<<product<<"\n\n\n";
    system("PAUSE");
    return EXIT_SUCCESS;
}


/*Program Preview*/


Friday, August 19

PROBLEM: Make a program that will accept an 'n' number of inputs in Binary Number System and counts the number of '1'. If the number of '1' is prime, it will print the input with its corresponding equivalent in Decimal Number System, else, return nothing.



#include <cstdlib>
#include <iostream>
#include <math.h>

using namespace std;

int main(int argc, char *argv[])
{
    long input,input1,input2;
    long A[100],B[100],I[100];
    long x,y,z,a=0,b,c=0,d=0,e,f,sum=0,i=0,j=0,num;
    cout<<"Number of Inputs:  ";
    cin>>num;
 
    for(;;){
         
            d=0;a=0;c=0;
            sum=0;
            if(j==num){break;}
    cout<<"\t->("<<i+1<<")Enter Binary:  ";
    cin>>input;
    I[i]=input;
    i++;
    for(;;){
            A[a]=input%10;
            b=input/10;
            a++;
            input=b;
            if(b==0){break;}
            }
    for(x=0;x<a;x++){
                      if(A[x]==1){c++;}
                      }
    for(z=c-1;z>1;z--){
                       if(c%z==0){d++;}
                       }
    if(d==0){
             for(f=0;f<a;f++){
             sum+=A[f]*pow(2,f);
             }
             }
             B[j]=sum;
             j++;
             }
    for(e=0;e<num;e++){
                       if(B[e]!=0){
    cout<<"\n\t\t"<<"Input"<<e+1<<": "<<I[e]<<"  |  "<<B[e]<<"\n";
                                     }
             }
           
             cout<<"\n\n\n";
           
    system("PAUSE");
    return EXIT_SUCCESS;
}



/*Program Preview*/


PROBLEM: Make a program that will receive a string input and print the letters that is prime repeated.


#include <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
    int c=0,d,x,y,z,L,e=0;
    char str[100];
    cout<<"Enter String: ";
    gets(str);
    L=strlen(str);
    cout<<"\n\n\tResult: ";
    for(x=0;x<L;x++){
                     for(y=0;y<L;y++){
                                      if(x==' '){continue;}
                                      if(y==x){continue;}
                                      if(str[x]==str[y]){c++;}
                                      }
                                      d=c+1;
                                      for(z=c;z>1;z--){
                                                         if(d%z==0){e++;}
                                                         }
                                                       
                   
                     if(e==0){cout<<str[x];}
                     c=0;
                     d=0;
                     e=0;
                                                       }
                                                       cout<<"\n\n\n";
                                                     
                                                     
    system("PAUSE");
    return EXIT_SUCCESS;
}


/*Program Preview*/


Monday, August 15

Problem Relating Factorial Using Turbo-C


Equation:
            4-(2/1!)+(3/2!)-(4/3!).......(n/n-1!)
 Sample:
           n=4/*number of series*/
           Equation: 4-(2/1!)+(3/2!)+(4/3!)
           Answer: 2.83333

 Solution:

float r,sum=0,facp;
    int n,o,p;
    printf("Enter Number: ");
    scanf("%d",&n);
    for(o=2;o<=n;o++){
        facp=1;
            for(p=o-1;p>1;p--){ facp*=p; }
                                r=o/facp;
                                if(o%2==0){r=r*(-1); sum+=r;}
                                else{ sum+=r;}
            }             
  printf("\n\n\tResult: %f\n\n\n",4+sum);



Replacing the Space By Underscore In A String Input Using Assembly Programming Language

.model small
.code
org 100h
jmp process
    parlist label byte
    maxlen db 30
    actlen db ?
    kbwill db 30 dup(' ')
   
    intro db 'Enter Word: ','$'
    storage db 30 dup(' ')

    out db 'Output: ','$'
input:
    mov ah,0ah
    lea dx,parlist
    int  21h
    ret
printing:
    mov ah,09h
    int 21h
    ret
clr_scr:
    mov ax,0600h
    mov bh,07h
    mov cx,0000h
    mov dx,184fh
    int 10h
    ret
set_cur:
    mov ah,02h
    mov bh,00h
    int 10h
    ret

process proc near
    call clr_scr
    mov dx,0000h
    call set_cur
    lea dx,intro
    call printing
    call input
    mov dx,0305h
    call set_cur
    mov si,00h
    mov di,00h
    mov ch,00h
    mov cl,actlen
    call processing
    mov dx,0505h
    call set_cur
    lea dx,out
    call printing
    mov storage[si],'$'
    lea dx,storage
    call printing
    int 20h
    process endp
    end process
processing:
    cmp si,cx
    je return
    mov dl,kbwill[si]
    cmp dl,' '
    je replace
    jne insert
return:
    ret
replace:
    mov storage[di],'_'
    inc di
    inc si
    jmp processing
insert:
    mov storage[di],dl
    inc di
    inc si
    jmp processing


/*Program Preview*/


Printing The Characters Of Two String Inputs In Alernating Manner Using Assembly Programming Language


.model small
.code
org 100h
jmp process
                parlist label byte
                maxlen db 30
                actlen db ?
                kbwill1 db 30 dup(' ')
               
                paralist label byte
                maxnlen db 30
                actnlen db ?
                kbwill2 db 30 dup(' ')
               
                intro1 db 'Enter Word1: ','$'
                intro2 db 'Enter Word2: ','$'
                storage db 60 dup(' ')
                mana db 'Press Any Key To Continue','$'
                rr db ?
                r1 db ?
               
input1:
                mov ah,0ah
                lea dx,parlist
                int  21h
                ret
input2:
                mov ah,0ah
                lea dx,paralist
                int  21h
                ret
printing:
                mov ah,09h
                int 21h
                ret
clr_scr:
                mov ax,0600h
                mov bh,07h
                mov cx,0000h
                mov dx,184fh
                int 10h
                ret
set_cur:
                mov ah,02h
                mov bh,00h
                int 10h
                ret

process proc near
                call clr_scr
                mov dx,0000h
                call set_cur
                lea dx,intro1
                call printing
                call input1
                mov dx,0100h
                call set_cur
                lea dx,intro2
                call printing
                call input2
                mov si,00h
                mov di,00h
                mov ch,00h
                mov cl,actlen
                mov al,actnlen
                mov ah,00h
                mov bx,0000h
                call processing
                mov dx,0505h
                call set_cur
                mov storage[bx],'$'
                lea dx,storage
                call printing
                mov dx,0905h
                call set_cur
                lea dx,mana
                call printing
                mov ax,071ch
                int 21h
                int 20h
                process endp
                end process
processing:
                 jmp word1
               
word1:
                cmp si,cx
                je compare2
                mov dl,kbwill1[si]
                mov storage[bx],dl
                inc si
                add bx,01h
                jmp word2
word2:
                cmp di,ax
                je compare1
                mov dl,kbwill2[di]
                mov storage[bx],dl
                inc di
                add bx,01h
                jmp processing
compare1:
                cmp si,cx
                je return
                jne word1
compare2:
                cmp di,ax
                je return
                jne word2
return:
                ret


/*Program Preview*/

Determining The Mean Character/s In A String Input Using Assembly Programming Language

.model small
.code
org 100h
jmp process
    parlist label byte
    maxlen db 30
    actlen db ?
    kbdata db 30 dup('')
    printf db 'Enter Word:','$'
   
    olabel db 'Mean Character/s: ','$'
process proc near
    call clr_scr
    mov dx,0000h
    call set_cur
    lea dx,printf
    call printing
    mov dx,0305h
    call set_cur
    call input
    mov dx,0605h
    call set_cur
    lea dx,olabel
    call printing
    call processing
process endp


input:
    mov ah,0ah
    lea dx,parlist
    int 21h
    cmp actlen,00h
    je term
    ret
term:
    int 20h
processing:
    mov dl,actlen
    shr dl,1
    mov bl,dl
    mov bh,00
    shl dl,1
    cmp dl,actlen
    je a30
    jne a20
a30:
    mov dl,kbdata[bx-1]
    call printing1
    mov dl,kbdata[bx]
    call printing1
    ret
   
a20:
    mov dl,kbdata[bx]
    call printing1
    ret
printing1:
    mov ah,02h
    int 21h
    ret
printing:
    mov ah,09h
    int 21h
    ret
clr_scr:
    mov ax,0600h
    mov bh,07h
    mov cx,0000h
    mov dx,184fh
    int 10h
    ret
set_cur:
    mov ah,02h
    mov bh,00h
    int 10h
    ret
end process

/*Program Preview*/



Sunday, August 14

Determining If The String Input Is Palindrome Or Not Using Assembly Programming Language


.model small
.code
org 100h
jmp process
                parlist label byte
                maxlen db 30
                actlen db ?
                kbdata db 30 dup('')
                intro db 'Enter Word','$'
                p db 'PALINDROME','$'
                np db 'NOT PALINDROME','$'
process proc near
                call clr_scr
                mov dx,0000h
                call set_cur
                call printing
                mov dx,0305h
                call set_cur
                call input
                mov dx,0505h
                call set_cur
                mov si,00
                mov bl,actlen
                mov bh,00h
                sub bx,01h
                mov di,bx
                call processing
process endp
input:
                mov ah,0ah
                lea dx,parlist
                int  21h
                cmp actlen,00h
                je term
                ret
term:
                int 20h
processing:
                cmp si,bx
                je printing1
                mov dh,kbdata[si]
                mov dl,kbdata[di]
                inc si
                dec di
                cmp dh,dl
                je processing
                jne printing2
               
printing1:
                mov ah,09h
                lea dx,p
                int 21h
                ret
printing2:
                mov ah,09h
                lea dx,np
                int 21h
                ret
printing:
                mov ah,09h
                lea dx,intro
                int 21h
                ret
clr_scr:
                mov ax,0600h
                mov bh,07h
                mov cx,0000h
                mov dx,184fh
                int 10h
                ret
set_cur:
                mov ah,02h
                mov bh,00h
                int 10h
                ret

end process


/*Program Preview*/

Separating Vowels And Consonants In A String Input Using Assembly Programming Language



.model small
.code
org 100h
jmp process
parlist label byte
maxlen db 30
actlen db ?
will db 30 dup(' ')
intro db 'Enter Word:','$'
con db 30 dup(' ')
vow db 30 dup(' ')
conlabel db 'Consonants:  ','$'
vowlabel db 'Vowels:      ','$'
input:
mov ah,0ah
lea dx,parlist
int  21h
cmp actlen,00h
je term
ret
term:
int 20h
printing:
mov ah,09h
int 21h
ret
clr_scr:
mov ax,0600h
mov bh,07h
mov cx,0000h
mov dx,184fh
int 10h
ret
set_cur:
mov ah,02h
mov bh,00h
int 10h
ret
process proc near
call clr_scr
mov dx,0000h
call set_cur
lea dx,intro
call printing
mov dx,0305h
call set_cur
call input
mov cl,actlen
mov ch,00
mov bx,0000
mov si,00
mov di,00
call processing
mov dx,0505h
call set_cur
lea dx,vowlabel
call printing
mov vow[si],'$'
lea dx,vow
call printing
mov dx,0605h
call set_cur
lea dx,conlabel
call printing
mov con[di],'$'
lea dx,con
call printing
jmp term
process endp
processing:
mov dl,will[bx]
cmp dl,'a'
je vowel
cmp dl,'e'
je vowel
cmp dl,'i'
je vowel
cmp dl,'o'
je vowel
cmp dl,'u'
je vowel
mov con[di],dl
inc di
bawo:
add bx,01h
cmp bx,cx
jne processing
ret
vowel:
mov vow[si],dl
inc si
jmp bawo

end process



/*This how the program is working*/