Sunday, February 19, 2017

Difference Between Two Numbers in Java

A simple program that I wrote using Java to ask the user to give two numbers and then our program will compute the difference between the two of them.

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 diff_two;


import java.util.Scanner;

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

    /**
     * @param args the command line arguments
     */
   public static int sub_two_number(int n1, int n2) {
      int sub=0;
      
      sub = (n1-n2);

      return sub;
   } 
    void display()
    {
       int num1=0, num2=0, sub_all=0;

        Scanner s = new Scanner(System.in);
     
        System.out.println();
        System.out.println("=== Difference of Two Numbers Using Method in Java === ");
        System.out.println();
      
         System.out.print("Enter First Value : ");
         num1 = s.nextInt();
            
         System.out.print("Enter Second Value : ");
         num2 = s.nextInt();
                 
         sub_all = sub_two_number(num1,num2);
  
        System.out.println();
        System.out.println("===== DISPLAY RESULTS ======");
        System.out.println();
        System.out.println("The difference betweem " + num1 + " and "
                     + num2 + " is " + sub_all + ".");

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





Addition of Two Numbers in Java

A simple program that I wrote using Java as my programming language that will ask the user to give two numbers and then our program will compute the sum of the two number being provided by our 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

addition_two.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 addition_two;


import java.util.Scanner;

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

    /**
     * @param args the command line arguments
     */
   public static int addition_two_number(int n1, int n2) {
      int sum=0;
      
      sum = (n1+n2);

      return sum;
   } 
    void display()
    {
       int num1=0, num2=0, sum_all=0;

        Scanner s = new Scanner(System.in);
     
        System.out.println();
        System.out.println("=== Addition of Two Numbers Using Method in Java === ");
        System.out.println();
      
         System.out.print("Enter First Value : ");
         num1 = s.nextInt();
            
         System.out.print("Enter Second Value : ");
         num2 = s.nextInt();
                 
         sum_all =  addition_two_number((num1,num2);
  
        System.out.println();
        System.out.println("===== DISPLAY RESULTS ======");
        System.out.println();
        System.out.println("The sum of " + num1 + " and "
                     + num2 + " is " + sum_all + ".");

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

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");
}