Saturday, April 9, 2016

Postfix To Prefix in Converter in C

A simple program that will convert a given expression by the user in postfix and then it will convert it into prefix equivalent in C programming language.


Add me at Facebook my address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com

My mobile number here in the Philippines is 09173084360.



Program Listing



#include <stdio.h>
#include <conio.h>
#include <string.h>

#define MAX 100

struct postfix
{
char stack[MAX][MAX], target[MAX] ;
char temp1[2], temp2[2] ;
char str1[MAX], str2[MAX], str3[MAX] ;
int i, top ;
} ;

void initpostfix ( struct postfix * ) ;
void setexpr ( struct postfix *, char * ) ;
void push ( struct postfix *, char * ) ;
void pop ( struct postfix *, char * ) ;
void convert ( struct postfix * ) ;
void show ( struct postfix ) ;

void main( )
{
struct postfix q ;
char expr[MAX] ;

clrscr( ) ;

initpostfix ( &q ) ;
     
        printf ( "\n POSTFIX TO PREFIX CONVERTER IN C " ) ;
        printf("\n\n");
printf ( "\nEnter an expression in postfix form: " ) ;
gets ( expr ) ;

setexpr ( &q, expr ) ;
convert ( &q ) ;

printf ( "\nThe Prefix expression is: " ) ;
show ( q ) ;

getch( ) ;
}


void initpostfix ( struct postfix *p )
{
p -> i = 0 ;
p -> top = -1 ;
strcpy ( p -> target, "" ) ;
}


void setexpr ( struct postfix *p, char *c )
{
strcpy ( p -> target, c ) ;
}


void push ( struct postfix *p, char *str )
{
if ( p -> top == MAX - 1 )
printf ( "\nStack is full." ) ;
else
{
p -> top++ ;
strcpy ( p -> stack[p -> top], str ) ;
}
}

void pop ( struct postfix *p, char *a )
{
if ( p -> top == -1 )
printf ( "\nStack  is empty." ) ;
else
{
strcpy ( a, p -> stack[p -> top] ) ;
p -> top-- ;
}
}


void convert ( struct postfix *p )
{
while ( p -> target[p -> i] != '\0' )
{
/* skip whitespace, if any */
if ( p -> target[p -> i] == ' ')
p -> i++ ;
if( p -> target[p -> i] == '%' || p -> target[p -> i] == '*' ||
p -> target[p -> i] == '-' || p -> target[p -> i] == '+' ||
p -> target[p -> i] == '/' || p -> target[p -> i] == '$' )
{
pop ( p, p -> str2 ) ;
pop ( p, p -> str3 ) ;
p -> temp1[0] = p -> target[ p -> i] ;
p -> temp1[1] = '\0' ;
strcpy ( p -> str1, p -> temp1 ) ;
strcat ( p -> str1, p -> str3 ) ;
strcat ( p -> str1, p -> str2 ) ;
push ( p, p -> str1 ) ;
}
else
{
p -> temp1[0] = p -> target[p -> i] ;
p -> temp1[1] = '\0' ;
strcpy ( p -> temp2, p -> temp1 ) ;
push ( p, p -> temp2 ) ;
}
p -> i++ ;
}
}


void show ( struct postfix p )
{
char *temp = p.stack[0] ;
while ( *temp )
{
printf ( "%c ", *temp ) ;
temp++ ;
}

}

Descending Numbers in C

Here is a sample program that I wrote a very long time a ago in C language that will ask a series of numbers and then it will sort the given numbers into descending order.

Add me at Facebook my address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com

My mobile number here in the Philippines is 09173084360.



Program Listing

#include <stdio.h>
#include <conio.h>

int main()
{
     int arr[100],i,j,element,no,temp;
     clrscr();
     printf("\nEnter the no of Elements: ");
     scanf("%d", &no);
     for(i=0;i<no;i++){
          printf("\n Enter Element %d: ", i+1);
          scanf("%d",&arr[i]);
     }
     for(i=0;i<no;i++){
          for(j=i;j<no;j++){
               if(arr[i] < arr[j]){
               temp=arr[i];
               arr[i]=arr[j];
               arr[j]=temp;
               }
           }
     }
     printf("\nSorted array:");
     for(i=0;i<no;i++){
          printf("\t%d",arr[i]);
     }
     getch();
}





Decimal To Hexadecimal in Python


A simple program that I wrote using Python programming language that will ask the user to give decimal number and then our program will convert the given number into its hexadecimal equivalent.

Add me at Facebook my address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com

My mobile number here in the Philippines is 09173084360.



Sample Program Output


Program Listing

def my_program():
   print()
   print("DECIMAL TO HEXADECIMAL CONVERTER")
   print()
   decimal = int(input("Enter a Number: "))
   print()
   print('The number {0} in Decimal is equivalent to '.format(decimal))
   print(hex(decimal), " in Hexadecimal.");
   print("\n");
   repeat = input('Do you want to continue ? (Y/N) : ')

   if repeat.upper() == "N":
       print("\n")
       print("END OF PROGRAM")
       quit
   if repeat.upper() == "Y":
       my_program()

if __name__ == '__main__':
       my_program()


Decimal To Octal Converter in Python

A simple program that I wrote using Python programming language that will ask the user to give decimal number and then our program will convert the given number into its octal equivalent.

Add me at Facebook my address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com

My mobile number here in the Philippines is 09173084360.



Sample Program Output


Program Listing

def my_program():
   print()
   print("DECIMAL TO OCTAL CONVERTER")
   print()
   decimal = int(input("Enter a Number: "))
   print()
   print('The number {0} in Decimal is equivalent to '.format(decimal))
   print(oct(decimal), " in octal.");
   print("\n");
   repeat = input('Do you want to continue ? (Y/N) : ')

   if repeat.upper() == "N":
       print("\n")
       print("END OF PROGRAM")
       quit
   if repeat.upper() == "Y":
       my_program()

if __name__ == '__main__':
       my_program()



Decimal To Binary Converter in Python

A simple program that I wrote using Python programming language that will ask the user to give decimal number and then our program will convert the given number into its binary equivalent.

Add me at Facebook my address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com

My mobile number here in the Philippines is 09173084360.



Sample Program Output

Program Listing

def convert_binary(values):
   
   if values > 1:
     convert_binary(values//2)
   print(values % 2,end = '')

def my_program():
   print()
   print("DECIMAL TO BINARY CONVERTER")
   print()
   decimal = int(input("Enter a Number: "))
   print()
   print('The number {0} in Decimal is equivalent to '.format(decimal))
   convert_binary(decimal);
   print(" in binary.");
   print("\n");
   repeat = input('Do you want to continue ? (Y/N) : ')

   if repeat.upper() == "N":
       print("\n")
       print("END OF PROGRAM")
       quit
   if repeat.upper() == "Y":
       my_program()

if __name__ == '__main__':
       my_program()


Kilometers To Miles Converter in Python

In this simple program it will ask the user to give the distance in kilometers and then our program will convert the given distance in miles into kilometers equivalent using Python as my programming language.

Add me at Facebook my address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com

My mobile number here in the Philippines is 09173084360.




Sample Program Output


Program Listing

def my_program():
   print()
   print("KILOMETERS TO MILES CONVERTER")
   print()
   kilometers = float(input("How many kilometer(s) ? : "))
   print()
   miles = (kilometers *  0.621371)
   print('%0.2f Kilometers(s) is equal to %0.2f Mile(s).' %(kilometers,miles))
   print("\n");
   repeat = input('Do you want to continue ? (Y/N) : ')

   if repeat.upper() == "N":
       print("\n")
       print("END OF PROGRAM")
       quit
   if repeat.upper() == "Y":
       my_program()

if __name__ == '__main__':
       my_program()





Miles To Kilometers Converter in Python

In this simple program it will ask the user to give the distance in Miles and then our program will convert the given distance in miles into kilometers equivalent using Python as my programming language.

Add me at Facebook my address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com

My mobile number here in the Philippines is 09173084360.



Sample Program Output


Program Listing

def my_program():
   print()
   print("MILES TO KILOMETERS CONVERTER")
   print()
   miles = float(input("How many miles? : "))
   print()
   kilometers = (miles * 1.60934)
   print('%0.2f Mile(s) is equal to %0.2f Kilometer(s).' %(miles,kilometers))
   print("\n");
   repeat = input('Do you want to continue ? (Y/N) : ')

   if repeat.upper() == "N":
       print("\n")
       print("END OF PROGRAM")
       quit
   if repeat.upper() == "Y":
       my_program()

if __name__ == '__main__':
       my_program()


Cube Numbers in Python

A simple program that I wrote using Python as my programming language that will ask the user to give a number and then our program will convert the give number by the user into cube number equivalent.

Add me at Facebook my address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com

My mobile number here in the Philippines is 09173084360.



Sample Program Output


Program Listing


def my_program():
   print()
   print("CUBE NUMBERS PROGRAM")
   print()
   number = int(input("Enter a Number : "))
   print()
   solve_cube = (number * number * number)
   print("The cube value of ",number, " is "
          ,solve_cube,".")
   print("\n");
   repeat = input('Do you want to continue ? (Y/N) : ')

   if repeat.upper() == "N":
       print("\n")
       print("END OF PROGRAM")
       quit
   if repeat.upper() == "Y":
       my_program()

if __name__ == '__main__':
       my_program()



Consonants Remover in Python


A simple program that  I wrote using Python as my programming language that will ask the user to give a word or a sentence and then our program will remove the consonants in the given word or a sentence by the user.

Add me at Facebook my address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com

My mobile number here in the Philippines is 09173084360.




Sample Program Output


Program Listing

def my_program():
   print()
   print("REMOVE CONSONANTS PROGRAM")
   print()
   str = input("Enter a String : ")
   print()
   consonants = ['b', 'c', 'd', 'f', 'g',
                 'h','j','k','l','m','n',
                 'p','q','r','s','t','v',
                 'w','x','y','z']
   result = ''
   for letter in str.lower():
      if letter not in consonants:
       result += letter
   print("The result is " ,result.upper(),".")
   print("\n");
   repeat = input('Do you want to continue ? (Y/N) : ')

   if repeat.upper() == "N":
       print("\n")
       print("END OF PROGRAM")
       quit
   if repeat.upper() == "Y":
       my_program()

if __name__ == '__main__':
       my_program()





Remove Vowels in Python

A simple program that  I wrote using Python as my programming language that will ask the user to give a word or a sentence and then our program will remove the vowels in the given word or a sentence.

Add me at Facebook my address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com

My mobile number here in the Philippines is 09173084360.



Sample Program Output


Program Listing


def my_program():
   print()
   print("REMOVE VOWELS PROGRAM")
   print()
   str = input("Enter a String : ")
   print()
   vowels = ['a', 'e', 'i', 'o', 'u']
   result = ''
   for letter in str.lower():
      if letter not in vowels:
       result += letter
   print("The result is " ,result.upper(),".")
   print("\n");
   repeat = input('Do you want to continue ? (Y/N) : ')

   if repeat.upper() == "N":
       print("\n")
       print("END OF PROGRAM")
       quit
   if repeat.upper() == "Y":
       my_program()

if __name__ == '__main__':
       my_program()



Saturday, April 2, 2016

Array in JavaScript

A very simple program to demonstrate how to declare and use array using JavaScript as our programming language.

Add me at Facebook my address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com

My mobile number here in the Philippines is 09173084360.


Program Listing

<html>
    <head>
        <title>Array in JavaScript</title>
    <head>
     <h1> Array in JavaScript </h1>
     <br> 
    </body>
        
        <script>

            var arrayOfFruits = ['Apple', 'Banana', 'Grapes', 'Orange','Guava','Dalandan'];
                
   
            alert(arrayOfFruits[2]);
            alert('length: ' + arrayOfFruits.length);            
        </script>
</html>

Focus Function in JavaScript

A simple program in JavaScript that shows how to use focus method in a program. The code is very basic and easy to understand for beginners that are new in JavaScript programming.

Add me at Facebook my address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com

My mobile number here in the Philippines is 09173084360.


Program Listing

<html>
    <head>
        <title> Focus method in JavaScript</title>
    <head>
         <h1> Focus Method in JavaScript </h1>
         <br>
    <body>      
    
        <input type="text" id="txtName"/>
        &nbsp;&nbsp;
        <input
               type = "button"
               id = "btnCompute"
               onclick = "Compute();"
               value = "Compute"/>
    </body>
        
    <script>
        function Compute() {
            var txtName = document.getElementById("txtName");
            var name = txtName.value;
            
            if (name.trim() == "") {
                alert("Please enter value for name. ");
                txtName.focus;
                
            } else {
                alert("Hello " + name + " ! ");
            }
        }
    </script>
</html>

High, Middle and Low Number Determiner in C++

This program will determine which of the three numbers given by our user is the Highest, Middle and Lowest Number in C++ just using if else statement and relational operator. The code is very simple and easy to understand.

Add me at Facebook my address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com

My mobile number here in the Philippines is 09173084360.


Program Listing

#include <iostream.h>

using namespace std;

int high_number(int value1,int value2, int value3) {

  int high_value=0,low_value=0,middle_value=0;

   // Check For Higher Number

  if (value1 >= value2 && value1 >= value3) {
        high_value = value1;

    }

    else if (value2 >= value1 && value2 >= value3) {
        high_value = value2;
    }

    else if (value3 >= value1 && value3 >= value2) {
        high_value = value3;
    }


// Check For Low Number

  if (value1 <= value2 && value1 <= value3) {
        low_value = value1;
    }

    else if (value2 <= value1 && value2 <= value3) {
        low_value = value2;
    }
    else if (value3 <= value1 && value3 <= value2) {
        low_value = value3;
    }


 // Check For Middle Value
 
  if (value1 <= value2 && value1 >= value3 ) 
         {
        
        middle_value = value1;
    }
else  if (value2 <= value1 && value2 >= value3) 
      
         {
        
        middle_value = value2;
    }
else  if (value3 <= value1 && value3 >= value2) 
         {
        
        middle_value = value3;
    }

// Code for check all the possible arrangement of values

 // Check for 1 value   
else  if (value1 >= value2 && value1 <= value3) 
         {
        
        middle_value = value1;
    }

 // Check for 2 value   
else  if (value2 >= value1 && value2 <= value3) 
         {
        
        middle_value = value2;
    }


 // Check for 3 value   
else  if (value3 >= value1 && value3 <= value2) 
         {
        
        middle_value = value3;
    }

    cout << "\n\n";
    cout <<"\n" << high_value << " is the biggest number.";
   cout <<"\n" << middle_value << " is the middle number.";
   cout << "\n" << low_value << " is the lowest number.";
    cout << "\n\n";
}

main() {

    int a=0,b=0,c=0;

    cout << "\t High, Middle and Low Number Determiner 1.0";
    cout << "\n\n \t Created By: Mr. Jake R. Pomperada,MAED-IT";
    cout << "\n\n"; 
    cout << "Enter a Number : ";
    cin >> a;
    cout << "Enter a Number : ";
    cin >> b;
    cout << "Enter a Number : ";
    cin >> c;
    high_number(a,b,c);
    system("PAUSE");

}