Friday, November 10, 2017

Linear Search in C

A program to show how to implement linear search in C language.

My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.

My telephone number at home here in Bacolod City, Negros Occidental is (034) 4335675.


Program Listing

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

void main( )
{
int arr[10] = { 1, 2, 3, 9, 11, 13, 17, 25, 57, 90 } ;
int i, num ;

printf ( "Enter number to search: " ) ;
scanf ( "%d", &num ) ;

for ( i = 0 ; i <= 9 ; i++ )
{
if ( arr[9] < num || arr[i] >= num )
{
if ( arr[i] == num )
printf ( "The number is at position %d in the array.", i ) ;
else
printf ( "Number is not present in the array." ) ;
break ;
}
}

}

Selection Sort in C

A program to demonstrate selection sort in C language.

I am currently accepting programming work kindly contact me in the following email address for further details. Thank you.

My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.

My telephone number at home here in Bacolod City, Negros Occidental is (034) 4335675.


Program Listing


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

void main( )
{
int arr[5] = { 125, 172, 313, 131, 23 } ;
int i, j, temp ;



printf ( "Selection sort.\n" ) ;
printf ( "\nArray before sorting:\n") ;

for ( i = 0 ; i <= 4 ; i++ )
printf ( "%d\t", arr[i] ) ;

for ( i = 0 ; i <= 3 ; i++ )
{
for ( j = i + 1 ; j <= 4 ; j++ )
{
if ( arr[i] > arr[j] )
{
temp = arr[i] ;
arr[i] = arr[j] ;
arr[j] = temp ;
}
}
}

printf ( "\n\nArray after sorting:\n") ;

for ( i = 0 ; i <= 4 ; i++ )
printf ( "%d\t", arr[i] ) ;

getch( ) ;
}

Quick Sort in C

A program to show quick sort algorithm in C language.

I am currently accepting programming work kindly contact me in the following email address for further details. Thank you.

My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.

My telephone number at home here in Bacolod City, Negros Occidental is (034) 4335675.


Program Listing


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

int split ( int*, int, int ) ;

void main( )
{
int arr[10] = { 11, 2, 9, 13, 57, 25, 17, 1, 90, 3 } ;
int i ;

void quicksort ( int *, int, int ) ;

printf ( "Quick sort.\n" ) ;
printf ( "\nArray before sorting:\n") ;

for ( i = 0 ; i <= 9 ; i++ )
printf ( "%d\t", arr[i] ) ;

quicksort ( arr, 0, 9 ) ;

printf ( "\nArray after sorting:\n") ;

for ( i = 0 ; i <= 9 ; i++ )
printf ( "%d\t", arr[i] ) ;

}

void quicksort ( int a[ ], int lower, int upper )
{
int i ;
if ( upper > lower )
{
i = split ( a, lower, upper ) ;
quicksort ( a, lower, i - 1 ) ;
quicksort ( a, i + 1, upper ) ;
}
}

int split ( int a[ ], int lower, int upper )
{
int i, p, q, t ;

p = lower + 1 ;
q = upper ;
i = a[lower] ;

while ( q >= p )
{
while ( a[p] < i )
p++ ;

while ( a[q] > i )
q-- ;

if ( q > p )
{
t = a[p] ;
a[p] = a[q] ;
a[q] = t ;
}
}

t = a[lower] ;
a[lower] = a[q] ;
a[q] = t ;

return q ;
}

Heap Sort in C

A program to show heap sort using C language.

I am currently accepting programming work kindly contact me in the following email address for further details. Thank you.

My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.

My telephone number at home here in Bacolod City, Negros Occidental is (034) 4335675.


Program Listing

heap.c

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

void makeheap ( int [ ], int ) ;
void heapsort ( int [ ], int ) ;

void main( )
{
int arr[10] = { 11, 2, 9, 13, 57, 25, 17, 1, 90, 3 } ;
int i ;

clrscr( ) ;
printf ( "Heap Sort.\n" ) ;

makeheap ( arr, 10 ) ;

printf ( "\nBefore Sorting:\n" ) ;
for ( i = 0 ; i <= 9 ; i++ )
printf ( "%d\t", arr[i] ) ;

heapsort ( arr, 10 ) ;

printf ( "\nAfter Sorting:\n" ) ;
for ( i = 0 ; i <= 9 ; i++ )
printf ( "%d\t", arr[i] ) ;

getch( );
}

void makeheap ( int x[ ], int n )
{
int i, val, s, f ;
for ( i = 1 ; i < n ; i++ )
{
val = x[i] ;
s = i ;
f = ( s - 1 ) / 2 ;
while ( s > 0 && x[f] < val )
{
x[s] = x[f] ;
s = f ;
f = ( s - 1 ) / 2 ;
}
x[s] = val ;
}
}

void heapsort ( int x[ ], int n )
{
int i, s, f, ivalue ;
for ( i = n - 1 ; i > 0 ; i-- )
{
ivalue = x[i] ;
x[i] = x[0] ;
f = 0 ;

if ( i == 1 )
s = -1 ;
else
s = 1 ;

if ( i > 2 && x[2] > x[1] )
s = 2 ;

while ( s >= 0 && ivalue < x[s] )
{
x[f] = x[s] ;
f = s ;
s = 2 * f + 1 ;

if ( s + 1 <= i - 1 && x[s] < x[s + 1] )
s++ ;
if ( s > i - 1 )
s = -1 ;
}
x[f] = ivalue ;
}
}

Insertion Sort in C

A program to show insertion sort using C language.

I am currently accepting programming work kindly contact me in the following email address for further details. Thank you.

My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.

My telephone number at home here in Bacolod City, Negros Occidental is (034) 4335675.


Program Listing

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

void main( )
{
int arr[5] = { 251, 17, 313, 135, 23 } ;
int i, j, k, temp ;

clrscr( ) ;

printf ( "Insertion sort.\n" ) ;
printf ( "\nArray before sorting:\n") ;

for ( i = 0 ; i <= 4 ; i++ )
printf ( "%d\t", arr[i] ) ;

for ( i = 1 ; i <= 4 ; i++ )
{
for ( j = 0 ; j < i ; j++ )
{
if ( arr[j] > arr[i] )
{
temp = arr[j] ;
arr[j] = arr[i] ;

for ( k = i ; k > j ; k-- )
arr[k] = arr[k - 1] ;

arr[k + 1] = temp ;
}
}
}

printf ( "\n\nArray after sorting:\n") ;

for ( i = 0 ; i <= 4 ; i++ )
printf ( "%d\t", arr[i] ) ;

getch( ) ;
}

Towers of Hanoi in C

A C program that shows how towers of Hanoi works.

I am currently accepting programming work kindly contact me in the following email address for further details. Thank you.

My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.

My telephone number at home here in Bacolod City, Negros Occidental is (034) 4335675.


Program Listing


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

void move ( int, char, char, char ) ;

void main( )
{
int n = 3 ;

clrscr( ) ;

move ( n, 'A', 'B', 'C' ) ;

getch( ) ;
}

void move ( int n, char sp, char ap, char ep )
{
if ( n == 1 )
printf ("\nMove from %c to %c ", sp, ep ) ;
else
{
move ( n - 1, sp, ep, ap ) ;
move ( 1, sp, ' ', ep ) ;
move ( n - 1, ap, sp, ep ) ;
}
}

Dictionary Program in C

A simulation of dictionary program using linked list in C.

I am currently accepting programming work kindly contact me in the following email address for further details. Thank you.

My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.

My telephone number at home here in Bacolod City, Negros Occidental is (034) 4335675.


Program Listing

dictionary.c

#include <stdio.h>
#include <conio.h>
#include <malloc.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

struct node
{
char data [ 20 ] ;
char m [ 5 ] [ 20 ] ;
int mcount ;
struct node * link ;
} ;

struct node * dic [ 26 ] ;

void add ( char * ) ;
int  search ( char * ) ;
void show( ) ;
void deldic( ) ;

void main( )
{
char word [ 20 ] , ch ;
int i ;

clrscr( ) ;

while ( 1 )
{
clrscr( ) ;
printf ( "\n\t\tDictionary\n" ) ;
printf ( "\n\t\t1.Add Word.\n" ) ;
printf ( "\t\t2.Search Word.\n" ) ;
printf ( "\t\t3.Show Dictionary.\n" ) ;
printf ( "\t\t0.Exit." ) ;
printf ( "\n\n\t\tYour Choice ") ;
scanf ( "%d", &ch ) ;

switch ( ch )
{
case 1 :

printf ( "\nEnter any word : " ) ;
fflush ( stdin ) ;
gets ( word ) ;
add ( word ) ;

break ;

case 2 :

printf ( "\nEnter the word to search : " ) ;
fflush ( stdin ) ;
gets ( word ) ;
i = search ( word ) ;
if ( ! i )
printf ( "Word does not exists." ) ;
getch( ) ;

break ;

case 3 :

show( ) ;
getch( ) ;

break ;

case 0 :

deldic( ) ;
exit ( 0 ) ;

default :

printf ( "\nWrong Choice" ) ;
}
}
}

void add ( char * str )
{
int i, j = toupper ( str [ 0 ] ) - 65 ;
struct node * r, * temp = dic [ j ], * q ;
char mean [ 5 ] [ 20 ], ch = 'y' ;

i = search ( str ) ;
if ( i )
{
printf ( "\nWord already exists." ) ;
getch( ) ;
return ;
}
q = ( struct node * ) malloc ( sizeof ( struct node ) ) ;
strcpy ( q -> data, str ) ;
q -> link = NULL ;

for ( i = 0 ; tolower ( ch ) == 'y' && i < 5 ; i++ )
{
fflush ( stdin ) ;
printf ( "\n\nEnter the meaning(s) : " ) ;
gets ( mean [ i ] ) ;
strcpy ( q -> m [ i ] , mean [ i ] ) ;
if ( i != 4 )
printf ( "\nAdd more meanings (y/n) " ) ;
else
printf ( "You cannot enter more than 5 meanings." ) ;
fflush ( stdin ) ;
ch = getche( ) ;
}

q -> mcount = i ;
if ( dic [ j ] == NULL || strcmp ( dic [ j ] -> data, str ) > 0 )
{
r = dic [ j ] ;
dic [ j ] = q ;
q -> link = r ;
return ;
}

else
{
while ( temp != NULL )
{
if ( ( strcmp ( temp -> data, str ) < 0 ) && ( ( strcmp ( temp -> link -> data, str ) > 0 ) ||
temp -> link == NULL ) )
{
q -> link = temp -> link ;
temp -> link = q ;
return ;
}
temp = temp -> link ;
}
}
}

int search ( char *str )
{
struct node *n ;
char temp1 [ 20 ] ;
char temp2 [ 20 ] ;
int i ;

n = dic [ toupper ( str [ 0 ] ) - 65 ] ;
strcpy ( temp2, str ) ;
strupr ( temp2 ) ;

while ( n != NULL )
{
strcpy ( temp1, n -> data ) ;

if (  strcmp ( strupr ( temp1 ), temp2 ) == 0 )
{
printf ( "\n%s\t\t%s", n -> data, n -> m [ 0 ] ) ;
for ( i = 1 ; i < n -> mcount ; i++ )
printf ( "\n\t\t%s", n -> m [ i ] ) ;
return 1 ;
}
n = n -> link ;
}
return 0 ;
}

void show( )
{
struct node *n ;
int i, j ;

printf ( "Word\t\tMeaning\n" ) ;
for ( i = 0 ; i <= 30 ; i++ )
printf ( "-" ) ;


for ( i = 0 ; i <= 25 ; i++ )
{
n = dic [ i ] ;
while ( n != NULL )
{
printf ( "\n%s\t\t%s", n -> data, n -> m [ 0 ] ) ;
for ( j = 1 ; j < n -> mcount ; j++ )
printf ( "\n\t\t%s", n -> m [ j ] ) ;
n = n -> link ;
}
}
}

void deldic( )
{
struct node *n, *t ;
int i ;

for ( i = 0 ; i <= 25 ; i++ )
{
n = dic [ i ] ;
while ( n != NULL )
{
t = n -> link ;
free ( n ) ;
n = t ;
}
}
}

Print 1 to 100 in C

A very simple program to display 1 to 100 on the screen using C language. I shows how to use for loop statement in C.

I am currently accepting programming work kindly contact me in the following email address for further details. Thank you.

My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.

My telephone number at home here in Bacolod City, Negros Occidental is (034) 4335675.



Sample Program Output



Program Listing

print.c

#include <stdio.h>

int main()
{

    int a=0;

    printf("\t\tPrint 1 to 100");
    printf("\n\n");

     for (a=1; a <=100; a+=1)
     {

         printf("%2d " ,a);
     }

     printf("\n\n");
     printf("\t\t===== End of Program =====");
     printf("\n\n");
     return 0;
}



Wednesday, November 8, 2017

Record Search System in PHP and MySQL


In this article I would like to share with you a sample program that I worked before that will search the record on an employee in the database I called this program Record Search System in PHP and MySQL. I hope you will like my work.

I am currently accepting programming work kindly contact me in the following email address for further details. Thank you.

My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.

My telephone number at home here in Bacolod City, Negros Occidental is (034) 4335675.





Sample Program Output



Sunday, November 5, 2017

Power of a Number in C#

In this article our program will ask the user to give the base and exponent value and then our program will solve the power value. I wrote this program using C# as my programming language.

I am currently accepting programming work kindly contact me in the following email address for further details. Thank you.

My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.

My telephone number at home here in Bacolod City, Negros Occidental is (034) 4335675.




Sample Program Output


Program Listing


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    public class Power_Number
    {

        public static int Power(int number, int exponent)
        {
            if (exponent == 0)
                return 1;
            else
                return number * Power(number, exponent - 1);
        }
    
        
        public static void Main()
        {

            int number = 0;
            int exponent = 0; 
            Console.WriteLine("Power of a Number in C# ");
            Console.Write("\n");
            Console.WriteLine("By Mr. Jake R. Pomperada, MAED-IT ");
            Console.Write("\n\n");
  
            Console.Write( "Give Base : " );
            number = Convert.ToInt32( Console.ReadLine() );
            Console.Write( "Give Exponent: " );
            exponent = Convert.ToInt32( Console.ReadLine() );

            Console.Write("\n\n");
            Console.Write("The result ");
            Console.Write("\n\n");
            Console.WriteLine( "{0} ^ {1}= {2} ",number,exponent, Power( number, exponent) );

            Console.Write("\n\n");
            Console.Write("\t Thank You For Using This Software.");
            Console.ReadKey();
        }


     
    }

    
}