Sunday, February 19, 2017

GCD and LCM of two integers using Euclids' Algorithm in Java


A simple program that I wrote using Java to solve the GCD and LCM of a given number of the user.

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

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

My mobile number here in the Philippines is 09173084360.




Sample Program Output


Program Listing

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package gcd_lcm;


import java.util.Scanner;

/**
 *
 * @authors Jake R. Pomperada and  Jacob Samuel F. Pomperada
 * Date : February 19, 2017  Sunday
 * Language : Java
 * IDE     : NetBeans
 */
public class gcd_lcm {

    /**
     * @param args the command line arguments
     */
    
    void display()
    {
       int num1=0, num2=0, gcd=0, lcm=0, remainder=0, numerator=0, denominator=0;

        Scanner s = new Scanner(System.in);
     
        System.out.println();
        System.out.println("===  GCD and LCM of two integers using Euclids' Algorithm in Java === ");
        System.out.println();
      
         System.out.print("Enter First Value : ");
         num1 = s.nextInt();
            
         System.out.print("Enter Second Value : ");
         num2 = s.nextInt();
                 
        if (num1 > num2)

        {
        numerator = num1;
        denominator = num2;
        }
    else

       {
        numerator = num2;
        denominator = num1;
       }

    remainder = numerator % denominator;

    while (remainder != 0)

    {

        numerator   = denominator;

        denominator = remainder;

        remainder   = numerator % denominator;

    }

    gcd = denominator;

    lcm = num1 * num2 / gcd;
  
        System.out.println();
        System.out.println("===== DISPLAY RESULTS ======");
        System.out.println();
        System.out.println("The GCD of " + num1 + " and "
                           + num2 + " is " + gcd + ".");

        System.out.println("The LCM of " + num1 + " and "
                           + num2 + " is " + lcm + ".");

        System.out.println();
        System.out.println("===== END OF PROGRAM ======");
        System.out.println();
    }
    
    public static void main(String[] args)
      {
        // TODO code application logic here
      gcd_lcm demo  = new gcd_lcm();
      demo.display();
            
    }
    
}




Summation of Odd and Even Numbers in Java

Here there I am very happy that more and move visitors visiting my site even though it is not earning but I am happy that more people benefited from my works and my friends works also who contribute their work in my website.

I this article I would like to share with you a sample program that will ask the user to give five numbers and then it will sum up all the odd and even numbers that the user given. I am using one dimensional array and methods in Java I hope you like my work. Thank you so much.

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

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

My mobile number here in the Philippines is 09173084360.





Sample Program Output


Program Listing

sum_odd_even.java

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package sum_odd_eve;


import java.util.Scanner;

/**
 *
 * @authors Jake R. Pomperada and Jacob Samuel F. Pomperada
 * Date : February 19, 2017  Sunday
 * Language : Java
 * IDE     : NetBeans
 */
public class sum_odd_even {

    /**
     * @param args the command line arguments
     */
    
    void display()
    {
         int val_items=0, total_sum_even = 0, total_sum_odd = 0;

        Scanner s = new Scanner(System.in);

        val_items =  5;
        int[] array_value = new int[val_items];

        System.out.println();
        System.out.println("=== SUMMATION OF ODD AND EVEN NUMBERS IN JAVA === ");
        System.out.println();
        for(int b = 0; b < val_items; b++)

        {
           System.out.print("Enter value in item no. " + (b+1) + " : ");
            array_value[b] = s.nextInt();
       }

        for(int b = 0; b < val_items; b++)

        {
            if(array_value[b] % 2 == 0)

            {

                total_sum_even +=  array_value[b];

            }

            else

            {

                total_sum_odd += array_value[b];
            }

        }
        System.out.println();
        System.out.println("===== DISPLAY RESULTS ======");
        System.out.println();
        System.out.println("The Total Sum  of Even Numbers is "
                  + total_sum_even + ".");

        System.out.println("The Total Sum  of Odd Numbers is "
                  + total_sum_odd + ".");
        System.out.println();
        System.out.println("===== END OF PROGRAM ======");
        System.out.println();
    }
    
    public static void main(String[] args)
      {
        // TODO code application logic here
      sum_odd_even demo  = new sum_odd_even();
      demo.display();
            
    }
    
}







Thursday, February 16, 2017

Largest of Three Numbers in C

In this article I would like to share with you a sample program that I wrote using C as my programming language that will ask the user to give three numbers and then our program will check and determine which of the three numbers is the largest in terms of value using if conditional statement in C.  The code is very easy to understand and use. I am using CodeBlocks as my text editor and Dev C++ as my C/C++ compiler in this sample program. Thank you.

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

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

My mobile number here in the Philippines is 09173084360.




Sample Program Output


Program Listing

#include <stdio.h>

int main()
{
    int a=0,b=0,c=0;

    printf("\n\n");
    printf("LARGEST OF THREE NUMBERS IN C");
    printf("\n\n");
    printf("Give three numbers : ");
    scanf("%d%d%d",&a,&b,&c);
    printf("\n\n");
     if (a>b) {
         if (a>c){
            printf("The Largest Number is %d",a);
         }
         else {
            printf("The Largest Number is %d",c);
         }
     }
         else if (b>c){
            printf("The Largest Number is %d",b);
         }
         else {
            printf("The Largest Number is %d",c);
         }
    printf("\n\n");
    printf("END OF PROGRAM");
    printf("\n\n");
     }


Factors of a Number in C

Hi there in this article I would like to share with you guys a sample program that I wrote using C as my programming language. Our program will ask the user to give a number and then our program will display the factors of the given number using For loop statement in C. The code is very short and easy to understand. I hope you will learned from it. Thank you.

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

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

My mobile number here in the Philippines is 09173084360.




Sample Program Output


Program Listing

#include <stdio.h>

int main()
{
    int number=0,a=0;

    printf("\n\n");
    printf("FACTORS OF A NUMBER IN C");
    printf("\n\n");
    printf("Give any integer number : ");
    scanf("%d",&number);
    printf("\n\n");
    printf("The Factors of %d are: ",number);
     for (a=1; a<=number; a++){
         if (number % a == 0){
            printf(" %2d ",a);
         }
     }
    printf("\n\n");
    printf("END OF PROGRAM");
    printf("\n\n");
}



Wednesday, February 15, 2017

Accessing Arrays and Pointers in C

In this article I would like to share with you a sample program that I wrote using C language that will ask the user to give five numbers and then our program will display the list of number being provided by our user using arrays and pointers as our data structure.

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

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

My mobile number here in the Philippines is 09173084360.



Sample Program Output


Program Listing

/* Author: Mr. Jake R. Pomperada,MAED-IT */
/* Date  : February 15, 2017             */
/* Language : C                          */

#include <stdio.h>

int main()
{
    int data[5], a=0;
    printf("\n\n");
    printf("\n\tACCESS ARRAYS AND POINTERS IN C");
    printf("\n\n");
    printf("Give Elements : ");
     for (a=0; a<5; ++a) {
        scanf("%d",data+a);
        }
    printf("\n\n");
    printf("List of Values you have given ");
    printf("\n\n");
      for (a=0; a<5; ++a) {
            printf("%d\n",*(data+a));
     }
    printf("\n\n");
    printf("\n\t   END OF PROGRAM");
    printf("\n\n");
}



Pyramid of Numbers in C

In this article I would like to share with you a sample program that will display a pyramid of numbers image using C as my programming language it uses three for loop statements in order to achieve the pyramid image. I am using CodeBlocks as my text editor and Dev C++ as my C and C++ compiler.

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

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

My mobile number here in the Philippines is 09173084360.



Sample Program Output


Program Listing

/* Author: Mr. Jake R. Pomperada,MAED-IT */
/* Date  : February 15, 2017             */
/* Language : C                          */

#include <stdio.h>

int main()
{
    int a=0,b=0,c=0;

    printf("\n\n");
    printf("\n\tPYRAMID OF NUMBERS IN C");
    printf("\n\n");

    for (a=1; a<=9; a++) {
        for (c=a; c<=9; c++)  {
            printf("  ");
        }
        for (b=1; b<=a; b++) {
            printf(" %2d ",b);
        }
        printf("\n");
    }
    printf("\n\n");
    printf("\n\t   END OF PROGRAM");
    printf("\n\n");
}


Tuesday, February 14, 2017

Binary To Octal Converter in C

Here is a simple program that I wrote using C as my programming language that will ask the user to give binary number and then our program will convert the given binary number into octal equivalent.

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

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

My mobile number here in the Philippines is 09173084360.





Sample Program Output


Program Listing

#include <stdio.h>
#include <math.h>

int Binary_Octal(long long binaryNumber)
{
    int octalNumber = 0, decimalNumber = 0, i = 0;

    while(binaryNumber != 0)
    {
        decimalNumber += (binaryNumber%10) * pow(2,i);
        ++i;
        binaryNumber/=10;
    }

    i = 1;

    while (decimalNumber != 0)
    {
        octalNumber += (decimalNumber % 8) * i;
        decimalNumber /= 8;
        i *= 10;
    }

    return octalNumber;
}

int main()
{
    long long binaryNumber;
    printf("\n==============================");
    printf("\nBinary To Octal Converter in C");
    printf("\n==============================");
    printf("\n\n");
    printf("Give a value in Binary : ");
    scanf("%lld", &binaryNumber);
    printf("\n\n");
    printf("The result is %lld in Binary = %d in Octal Value.", binaryNumber, Binary_Octal(binaryNumber));
    printf("\n\n");
    printf("THANK YOU FOR USING THIS PROGRAM");
    printf("\n\n");
}






Password Security in C

Hi guys in this article I would like to share with you a sample program that I wrote that will ask the user to give a password and check if the given password is valid or not. What is good about this program it does not display the password while the user is type it instead it display the asterisk symbol in order to hide the real password to the user. The code is very simple and short I hope you will find my work useful.  I am using Dev C++ as my C++ compiler in this program. Thank you.

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

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

My mobile number here in the Philippines is 09173084360.




Sample Program Output


Program Listing


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

int main()
{
    char buffer[256] = {0};
    char password[] = "admin";
    char c;
    int pos = 0;

    printf("\n==============================");
    printf("\nPassword Security in C");
    printf("\n==============================");
    printf("\n\n");

     printf("%s", "Give Your Password: ");
    do {
        c = getch();

        if( isprint(c) )
        {
            buffer[ pos++ ] = c;
            printf("%c", '*');
        }
        else if( c == 8 && pos )
        {
            buffer[ pos-- ] = '\0';
            printf("%s", "\b \b");
        }
    } while( c != 13 );

    if( !strcmp(buffer, password) )

    {
        printf("\n\n");
        printf("Password is Accepted.");
        printf("\n\n");
    }
    else
         {
        printf("\n\n");
        printf("Intruder has been detected.");
        printf("\n\n");
    }
        printf("\n\n");
        printf("THANK YOU FOR USING THIS PROGRAM");
        printf("\n\n");
}





Sunday, February 12, 2017

Count Words in C

In this article I would like to share with you a sample program that will ask you to give a string and then our program will count the number of words in the given by the user using C as our programming language. The code is very short and easy to understand. Thank you.

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

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

My mobile number here in the Philippines is 09173084360.





Sample Program Output


Program Listing
 
word.c

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

#define NIL ' '

int main()
{

    char str[200];
    int count=0,a=0;

    printf("\t COUNT WORDS IN C PROGRAM");
    printf("\n\n");
    printf("\t Written By: Mr. Jake R. Pomperada, MAED-IT");
    printf("\n\n");
    printf("Give a String : ");
    scanf("%[^\n]s",&str);
     for (a=0;str[a] !='\0'; a++)
     {
        if (str[a]==NIL)
            {
              count++;
            }
     }
     printf("\n\n");
     printf("\t Display Results ");
     printf("\n\n");
     printf("The number of words in the given string is %d.",count+1);
     printf("\n\n");
     printf("\t End of Program ");
     printf("\n\n");
     return 0;
}