Showing posts with label Reverse. Show all posts
Showing posts with label Reverse. Show all posts

Reverse of a String and Number of Vowels - Java Program - Scanner


Reverse of a String and Number of Vowels  
 Scanner -Java Program
Program: Reverse.java
import java.util.Scanner;
class Reverse 
{
public static void main(String args[])
{
 String string,reverseString = "";
 int vowelCount=0;
 
   Scanner sc=new Scanner(System.in);
   System.out.print("Enter the word: ");
   string= sc.nextLine();
   
   for(int i=string.length()-1;i>=0;i--)
   {
    char ch=string.charAt(i);
    reverseString+=ch;
    if(ch=='A'||ch=='a'||ch=='E'||ch=='e'||ch=='I'||ch=='i'||ch=='O'||ch=='o'||ch=='U'||ch=='u')
    vowelCount++;
   }
   
   
   System.out.println("Reverse: "+reverseString+"\nNumber of vowels: "+vowelCount);
   
}
}

Output:
Enter the word: 2k8cse
Reverse: esc8k2
Number of vowels: 1

FIND REVERSE OF EACH WORD IN A STRING - Assembly Language - MASM

Program:

        ;FIND REVERSE OF EACH WORD IN A STRING


.model small
.stack 200h
.data
msg1 db 10,13,'Enter the string:$'
msg2 db 10,13,'Reverse of the string:$'
newline db 10,13,' $'
buff db 60 dup(?)
flag db 0
stackempty db 1
.code
print macro msg
push ax
push dx
mov ah,09h
mov dx,offset msg
int 21h
pop dx
pop ax
endm
.startup
print msg1
print newline
mov si,offset buff
mov cx,0
mov bx,0
nxtchar:
mov ah,01h
int 21h
inc bx
cmp al,' '
je popy
cmp al,0dh
je popy
mov ah,0
push ax
mov stackempty,0
inc cx
jmp nxtchar
popy:
cmp stackempty,1
je stackkaali
cmp al,0dh
jne noflag
mov flag,1
noflag:
pop ax
mov [si],al
inc si
loop noflag
inc si
mov stackempty,1
cmp flag,1
je display
jmp nxtchar
stackkaali:
inc si
jmp nxtchar
display:
print msg2
print newline
mov si,offset buff
mov cx,bx
dispnxt:mov dh,0
mov dl,[si]
mov ah,2
int 21h
inc si
loop dispnxt
.exit
End
OUTPUT
F:\>rev
Enter the string:
kerala is called gods own country
Reverse of the string:
alarek si dellac sdog nwo yrtnuoc

Reverse of a String - Assembly Language - MASM


REVERSE OF A STRING

Program:
.model small
.stack 200h
.data
   msg1 db 10,13,"Enter string:",10,13,'$'
   msg2 db 10,13,"Reverse of the string is:",10,13,'$'
   arr db 20 dup(?)
.code
   print MACRO msg
   PUSH AX
   PUSH DX
   MOV AH,09H
   MOV DX,offset msg
   INT 21H
   POP DX
   POP AX
   ENDM
.startup
   print msg1
   mov arr,18
   mov dx,offset arr
   mov ah,0ah
   int 21h
   lea dx,msg2
   mov ah,09h
   int 21h
   mov ch,0h
   mov cl,arr[1]
   mov di,cx
   inc di
l1:
   mov dl,arr[di]
   mov ah,02h
   int 21h
   dec di
   loop l1
  .exit
End

Output:
F:\>revv
Enter string:
PALINDROME
Reverse of the string is:
EMORDNILAP

Sum of Digits & Number of Digits - Assembly Language - MASM


Number of Digits, Sum of Digits & Reverse of a Number
 

Program:
.model small
.stack 200h
.data
   msg1 db "Enter the number::$"
   msg2 db 'Sum of digits is::$'
   msg3 db 'No. of digits is::$'
   msg4 db 10,13,"Reverse of the given number is::$"
   newline DB 10,13, ' $'
   sum dw 0
   NO dW 0
   cnt dw 0
   arr db 20 dup(?)
.code
   print MACRO msg
   push ax
   push dx
   mov ah,09h
   mov dx,offset msg
   INT 21H
   pop dx
   pop ax
ENDM
.startup
   print msg1
   call readnumtoAX
   print msg4
   mov cx,ax
   mov BX,10
   mov si,offset arr
   mov di,offset arr
DV1:
   mov ax,cx
   mov dh,00
   mov dl,00
   div BX
   mov cx,ax
   inc NO
   mov al,dl
   mov [si],al
   mov ah,00
   call displayAX
   inc si
   add SUM,DX
   mov ax,cx
  cmp    AX,0
  jne DV1
  mov AX,NO
   print newline
   print msg3
   CALL displayAX
   MOV AX,SUM
   print newline
   print msg2
CALL displayAX
  print newline
   ;mov cx,NO
  ;dis:
   ; mov ah,00
   ; mov al,arr[di]
   ; CALL displayAX
   ;inc di
   ;loop dis
.EXIT
readnumtoAX PROC NEAR
   PUSH BX
   PUSH CX
   MOV CX,10
   MOV BX,00
back:
   MOV AH,01H
   INT 21H
   CMP AL,'0'
   JB skip
   CMP AL,'9'
   JA skip
   SUB AL,'0'
   PUSH AX
   MOV AX,BX
   MUL CX
   MOV BX,AX
   POP AX
   MOV AH,00
   ADD BX,AX
   JMP back
skip:
   MOV AX,BX
   POP CX
   POP BX
   RET
readnumtoAX ENDP
displayAX PROC NEAR
   PUSH DX
   PUSH CX
   PUSH BX
   PUSH AX
   MOV CX,0
   MOV BX,10
back1:
   MOV DX,0
   DIV BX
   PUSH DX
   INC CX
   OR AX,AX
   JNZ back1
back2:
   POP DX
   ADD DL,30H
   MOV AH,02H
   INT 21H
   LOOP back2
   POP AX
   POP BX
   POP CX
   POP DX
   RET
displayAX ENDP
END

Output:
F:\>unt
Enter the number::7835
Reverse of the given number is::5387
No. of digits is::4
Sum of digits is::23

Sum of Digit & Reverse of a Number - C Program

Program:
#include<stdio.h>
//#include<conio.h>
void main()
{
    int r=0,n,sum=0,d;
    printf("Enter the number:");
    scanf("%d",&n);
    while(n>0)
    {
      d=n%10;
      sum=sum+d;
      r=(r*10)+d;
      n=n/10;
    }
    printf("\n sum of digits= %d",sum);
    printf("\n Reverse=%d",r);
    printf("\n");
//getch();
}

Output:
nn@linuxmint ~ $ gcc c24.c
nn@linuxmint ~ $ ./a.out
Enter the number:15

 sum of digits= 6
 Reverse=51
nn@linuxmint ~ $
Related Posts Plugin for WordPress, Blogger...