Saturday, November 21, 2015

Radix Sort in JavaScript

This program will show you how to implement Radix Sort algorithm using JavaScript programming language.

If you  have some questions please send me an email at jake.r.pomperada@gmail.com and jakerpomperada@yahoo.com

My mobile number here in the Philippines is 09173084360.



Sample Program Output



Program Listing

<html>
 <head>
   <title>Radix Sort</title>
  </head>
<body> 
   <script>

   var values=[],a=[];
   var temp=0,pos=0;
   
   document.write("<font face='arial' size='4'>RADIX SORT </font>");
   document.write("<br><br>");
 for (a=0; a<10; a++) {
  values.push(Number(prompt("Enter item value at no. " + (a+1))));
   }
      document.write("<font face='arial' size='4'>Numbers");
     document.write(" given by the user </font>");
     document.write("<br><br>");
  for (a=0;a<10; a++) {
    document.write("<font face='arial' size='4'> " +values[a] + "");
   }

function radix_sort (A) {
var k = Math.max.apply(null, A.map(function(i) {
    return Math.ceil(Math.log(i)/Math.log(2));
}));

for (var d = 0; d < k; ++d) {
    for (var i = 0, p = 0, b = 1 << d, n = A.length; i < n; ++i) {
        var o = A[i];
        if ((o & b) == 0) {
            A.splice(p++, 0, A.splice(i, 1)[0]);
       }
   }
}
return A;
}

      radix_sort(values);

      document.write("<br><br>");
 document.write("<font face='arial' size='4'>Sorted List of Numbers </font>");
 document.write("<br><br>");
 
  for (a=0; a<10; a++) {
    document.write("<font face='arial' size='4'> " +  values[a]+"</font>");
  }  
  </script>
  </body>
 </html>  
   


Least Common Denominator in JavaScript

A simple least common denominator in JavaScript that will ask a number and determine the least common denominator  values of the number.

If you  have some questions please send me an email at jake.r.pomperada@gmail.com and jakerpomperada@yahoo.com

My mobile number here in the Philippines is 09173084360.



Sample Program Output


Program Listing

<html>
 <head>
   <title> Least Common Denominator </title>
  </head>
  <style>
  h3 {
     font-family:arial;
 </style>
 <body> 
 <h3> Least Common Denominator </h3>
 <script>

 function LCM(A)  
{   
    var n = A.length, a = Math.abs(A[0]);
    for (var i = 1; i < n; i++)
     { var b = Math.abs(A[i]), c = a;
       while (a && b){ a > b ? a %= b : b %= a; } 
       a = Math.abs(c*A[i])/(a+b);
     }
    return a;
}

 val_1 = Number(prompt("Enter First Number  : "));
 val_2 = Number(prompt("Enter Second Number : "));


document.write("<font face='arial' face='14'> <b>");
document.write("The Least Common Denomination of " + val_1 + " and " + val_2 
  + " is " + LCM([val_1, val_2])+". <b></font>"); 
</script>
</body>
</html>





Square Root Calculator in JavaScript

A simple program that I wrote that will compute the square root of a number in JavaScript. The code is very simple  and easy to understand.

If you  have some questions please send me an email at jake.r.pomperada@gmail.com and jakerpomperada@yahoo.com

My mobile number here in the Philippines is 09173084360.



Sample Program Output


Program Listing

<html>
<title> Square Root Calculator in JavaScript</title>
<body>
<center>
 <script>
 function calcsqrt(form) 
{
var number=form.number.value;
var ans=Math.sqrt(number);
if (number<0) ans="Invalid";
form.sqrt.value=ans;
}
 </script>
<table width="40%" border="8" cellpadding="5" cellspacing="15" bgcolor="lightgreen">
        <tr>
           <td align="center" ><h3> <font face="comic sans ms" color="blue" >Square Root Calculator </font></h3>
                <form action="#" method="get" name="form">
                  <font size="4" face="comic sans ms" color="blue">&radic;</font><input name="number" type="text" class="regfont" size="6"/>
                  <br /><br /><input type="button" onclick="calcsqrt(this.form)" value="Find the Square Root"/>
                  <br /><br /><font face="comic sans ms" color="blue"> 
 The Square Root Value is:<input name="sqrt" type="text" class="regfont" size="20"/><br /><br />
               </form>
           </td>
        </tr>
    </table>
  </center>
  </body>
  </html>



Greeter Program in JavaScript

A simple program that we ask the name of the user and then our program will greet the user using JavaScript. The code is very simple and easy for beginners in JavaScript programming.

If you  have some questions please send me an email at jake.r.pomperada@gmail.com and jakerpomperada@yahoo.com

My mobile number here in the Philippines is 09173084360.


Sample Program Output


Program Listing

<html>
<head>
<title> Gretter Program </title>
</head>
<style>
body {
  font-family:arial;
  font-size:16px;
  }
</style>
<script type="text/javascript">
function user_name () {
    var txtName = form.txt_name.value;
    var message = "Hello " + "<b>"+ txtName +"</b>"+ " How are you today?";
 
document.getElementById("user").innerHTML = message;
}
function clear_all() {
  document.getElementById("user").innerHTML = " ";
   form.txt_name.value=" ";
   form.txt_name.focus();
 }
</script>
</head>
<body>
<form name="form" method="post">
Enter your name 
<input type="text" name="txt_name"  size="15"><br><br>
<input type="button" onclick="user_name()" value="Ok">
<input type="button" onclick="clear_all()" value="Clear">
<br><br>
  <div id="user"> </div>
</form>
</body>
</html>

Currency Converter in JavaScript

A simple program that I wrote in JavaScript that will convert currency value into other currencies. The code is very simple and easy to understand.

If you  have some questions please send me an email at jake.r.pomperada@gmail.com and jakerpomperada@yahoo.com

My mobile number here in the Philippines is 09173084360.


Sample Program Output


Program Listing

<html>
<body bgcolor="white" >
<font face="comic sans ms">
<script language="JavaScript">
<!--
function euroConverter(){
document.converter.dollar.value = document.converter.euro.value * 1.470
document.converter.pound.value = document.converter.euro.value * 0.717
document.converter.yen.value = document.converter.euro.value * 165.192
}
function dollarConverter(){
document.converter.euro.value = document.converter.dollar.value * 0.680
document.converter.pound.value = document.converter.dollar.value * 0.488
document.converter.yen.value = document.converter.dollar.value * 112.36
}
function poundConverter(){
document.converter.dollar.value = document.converter.pound.value * 2.049
document.converter.euro.value = document.converter.pound.value * 1.394
document.converter.yen.value = document.converter.pound.value * 230.27
}
function yenConverter(){
document.converter.dollar.value = document.converter.yen.value * 0.0089
document.converter.pound.value = document.converter.yen.value * 0.00434
document.converter.euro.value = document.converter.yen.value * 0.00605
}
//-->
</script>
<h3>  Currency Converter 1.0 </h3>
<form name="converter">
<table border="0">
<tr>
<td>Euro: </td><td><input type="text" name="euro" onChange="euroConverter()" /></td>
</tr>
<tr>
<td>US Dollar: </td><td><input type="text" name="dollar" onChange="dollarConverter()" /></td>
</tr>
<tr>
<td>British Pound:</td><td><input type="text" name="pound" onChange="poundConverter()" /></td>
</tr>
<tr>
<td>Japanese Yen: </td><td><input type="text" name="yen" onChange="yenConverter()" /></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="button" value="Convert!" /></td>
</tr>
</table>
</form>

</body>
</html>



Two Dimensional Array Demo in C

A simple program that I wrote in C language that demonstrate how to use Two Dimensional Array. The code is very simple and easy to understand perfect for beginners in C programming.

If you  have some questions please send me an email at jake.r.pomperada@gmail.com and jakerpomperada@yahoo.com

My mobile number here in the Philippines is 09173084360.



Sample Program Output


Program Listing

#include <stdio.h>

 main()
{
    int arr[5][1], i=0, j=0, sum=0;

    printf("Two Dimensional Array Demo");
    printf("\n\n");
    for(i=0;i<5;i++)
    {
        for(j=0;j<1;j++)
        {
            printf("\nEnter the value for A[%d][%d] : ",i,j);
            scanf("%d",&arr[i][j]);
    }
    }

    for(i=0;i<5;i++)
    {
        for(j=0;j<1;j++)
        {
        sum=sum+arr[i][j];
        }
    }

    printf("\nThe sum of the elements of 2-D array is %d.", sum);
    printf("\n\n");
    printf("End of Program");
}



Two Dimensional Array in C Using Initialized Values

A simple program that I wrote in C programming language that shows how to declare and display initialized values using two dimensional array and for loop statement.

If you  have some questions please send me an email at jake.r.pomperada@gmail.com and jakerpomperada@yahoo.com

My mobile number here in the Philippines is 09173084360.


                                                            
                                                   Sample Program Output


Program Listing


#include <stdio.h>

main()
 {
     int a[3][2] = {  {1,2},
                      {3,4},
                      {5,6}
                    };
int row=0,col=0;
  for (row=0; row<3; row++) {
        for (col=0; col<2; col++) {
            printf(" %d ",a[row][col]);

        }

     }
 }

Two Dimensional Array in C language

Simple program that I wrote in C language to demonstrate how to display initialize values in two dimensional array in C.

If you  have some questions please send me an email at jake.r.pomperada@gmail.com and jakerpomperada@yahoo.com

My mobile number here in the Philippines is 09173084360.



Sample Program Output


Program Listing

#include <stdio.h>

main()
 {
     int a[3][2] = {1,2,3,4,5,6};
     int row=0,col=0;

       for (row=0; row<3; row++) {
        for (col=0; col<2; col++) {
            printf(" %d ",a[row][col]);

        }

     }

 }


Multiplication Table in C

Here is a very short and simple program that I wrote using C programming language I called this program multiplication table using C. In this program I am using CodeBlocks as my text editor and Dev C++ as my C compiler. The code I'm just using two for loop or nested loop to generate multiplication table. I hope you will find my work useful in your quest in learning C programming language.

If you  have some questions please send me an email at jake.r.pomperada@gmail.com and jakerpomperada@yahoo.com

My mobile number here in the Philippines is 09173084360.








Sample Program Output


Program Listing

#include <stdio.h>

main()
{
int x=0,y=0;

printf("\t\t Multiplication Table");
printf("\n\n");
for ( x=1; x<=12; x++) {
         printf("\n");
        for (y=1; y<=12; y++) {
         printf(" %3d " ,x * y);

        }
    }
 printf("\n\n");
}






Thursday, November 19, 2015

Input and Display values in C using Two Dimensional Array



A simple program that I wrote using C language to show basic input and output using Two dimensional array as our data structure in C programming language.


If you  have some questions please send me an email at jake.r.pomperada@gmail.com and jakerpomperada@yahoo.com

My mobile number here in the Philippines is 09173084360.




Program Listing

#include <stdio.h>

main()
 {
     int value[3][2],a=0,b=0;


     for (a=0; a<3; a++)
        {
       for (b=0; b<2; b++) {
        printf("Enter value in item no. %d :",value[a][b]);
        scanf("%d",&value[a]);
         }
     }
     printf("\n\n");
     printf("List of values you have given");
     printf("\n\n");
     for (a=0; a<3; a++)
        {
       for (b=0; b<2; b++) {
        printf(" %d ",value[a][b]);
         }
     }
     printf("\n\n");
     system("pause");
 }

Highest and Lowest Number in C Using Two Dimensional Array

A program that I wrote that will ask the use to give five numbers and then our program will check which of the five numbers is the smallest and the highest in terms of values using two dimensional array in C language.

If you  have some questions please send me an email at jake.r.pomperada@gmail.com and jakerpomperada@yahoo.com

My mobile number here in the Philippines is 09173084360.





Sample Program Output


Program Listing

#include <stdio.h>

main()
 {
     int value[5][1],a=0,b=0,highest=0,lowest=0;
     int c[5][1] = {1,2,3,4,5};
     for (a=0; a<5; a++) {
       for (b=0; b<1; b++) {
        printf("Enter value in item no. %d :",c[a][b]);
        scanf("%d",&value[a][b]);
     }
     }
     printf("\n\n");
     printf("List of values you have given");
     printf("\n\n");
     highest=value[0][0];
    for (a=0; a<5; a++) {

for (b=0; b<1; b++){
         if(highest<value[a][b])
           highest=value[a][b];
     }
    }

   lowest =value[0][0];
     for (a=0; a<5; a++) {
      for (b=0; b<1; b++){
         if(lowest>value[a][b])
          lowest=value[a][b];
       }
     }
     printf("Highest Number :  %d. ",highest);
     printf("\n\n");
     printf("Lowest Number :  %d. ",lowest);
     printf("\n\n");

 }



Highest and Lowest Number Checker in C

A simple program that I wrote to ask the user to give five numbers and then our program will determine and display the highest and the lowest number.

If you  have some questions please send me an email at jake.r.pomperada@gmail.com and jakerpomperada@yahoo.com

My mobile number here in the Philippines is 09173084360.




Sample Program Output


Program Listing

#include <stdio.h>
#include <stdlib.h>
main()
 {
     int value[5],a=0,b=0,highest=0,lowest=0;
     system("cls");
     for (a=0; a<5; a++) {
        printf("Enter value in item no. %d :",a+1);
        scanf("%d",&value[a]);
     }
     printf("\n\n");
     printf("List of values you have given");
     printf("\n\n");
     highest=value[b];
     for (b=0; b<5; b++){
         if(highest<value[b])
           highest=value[b];
     }
     lowest =value[0];
      for (b=0; b<5; b++){
         if(lowest>value[b])
          lowest=value[b];
     }
     printf("Highest Number :  %d. ",highest);
     printf("\n\n");
     printf("Lowest Number :  %d. ",lowest);
     printf("\n\n");
     system("pause");

 }