Wednesday, July 8, 2015

Square Number Values in C language


We are started learning how to write a computer program we learn the fundamentals of programming. This fundamentals are very important because we cannot solve the problem without proper understanding the basic concepts of programming. One of the basic concepts is the study of sequence, variable declarations and the use of iteration or looping statements.  When we talking about sequence we are referring the basic structure of our program the library statements that we declare prior we declare any single variable in our program. 

As a programmer it is also our responsibility to know and understand what type of variables and its corresponding data types to be used in our program. If we don’t know the variable and data type we can use we can generate errors in our program by providing erroneous data and the output information that will generate by our program in also incorrect.

As we said our computer is a tool and machine very dependent to its users and the programs that runs on it. I have also mention the use of iteration or looping statements. This structure in programming is very important also because it minimize the number of lines of code that we use in our program by using this structure we can cut down the number of lines of our codes and the repetitive commands and routine that our program will be perform.

In this article I will discuss another program that I wrote for my class programming activity using C programming language I called this program Square Number Values. This program is very simple yet it show how to use variable declaration, the use of pointers and string declaration. What the program will do is to ask or prompts the user to enter five numbers and then the program will square those values that are being provided by the user and then display the result in the screen. The compiler that I used in this program in Code::Block editor that has a build in compiler called Dev C++ that is freely available to download over the Internet free from any charge.

The first portion of our program code is that it will accept input values from the user. For your information I declare three variables in our program the x,y and the character pointer string that I named words which is also declared as one dimensional array.  What is pointer string will do every time our looping statement run or execute it put string value for example 1 it will attach the string value of st so the output will be 1st, 2nd,3rd,4th and finally the 5th for the input values for the user given to our program.

#include <stdio.h>
#include <stdlib.h>

main()
{
    int x=0,y=0;
    char *words[5] = {"st", "nd","rd","th","th"};
    int values[5];
       printf("\n\n");
       printf("\t ======[SQUARE NUMBER VALUES]=======");
       printf("\n\n");
       for (x=0; x<5; x++)
       {
        printf("Enter %d%s Number : ",x+1,words[x]);
        scanf("%d",&values[x]);
       }

Here is the second and the last portion of our program code what our program will do is to list the values given by the user and then our program will multiply the number b y itself in order to generate its square value equivalent again we are using one dimensional array as our data structure just to gather whose values previously given by our user of our program and also to display the list of values and its computed square values. After that our program will thank the user for using our program and will terminated the operation of our program and return to our windows operating system.

  printf("\n\n");
    printf(" Original Value     Square Values");
    printf("\n\n");
       for (x=0; x<5; x++)
        {
           printf("\n %7d      %13d",values[x], values[x] * values[x]);
        }
    printf("\n\n");
    printf("\t Thank you for using this program.");
    printf("\n\n");
    system("pause");
}

I hope in this article you have learned something the use of variable declaration, understand the usage of pointers and strings and finally the iteration and looping statements to generate square number values. If you have some questions feel free send me an email I am very glad to answer your questions about the articles that I wrote in this website.

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


People here in the Philippines can reach me at my mobile number 09173084360.


Thank you very much and Happy Programming.



Sample Program Output



 Program Listing

#include <stdio.h>
#include <stdlib.h>

main()
{
    int x=0,y=0;
    char *words[5] = {"st", "nd","rd","th","th"};
    int values[5];
       printf("\n\n");
       printf("\t ======[SQUARE NUMBER VALUES]=======");
       printf("\n\n");
       for (x=0; x<5; x++)
       {
        printf("Enter %d%s Number : ",x+1,words[x]);
        scanf("%d",&values[x]);
       }
    printf("\n\n");
    printf(" Original Value     Square Values");
    printf("\n\n");
       for (x=0; x<5; x++)
        {
           printf("\n %7d      %13d",values[x], values[x] * values[x]);
        }
    printf("\n\n");
    printf("\t Thank you for using this program.");
    printf("\n\n");
    system("pause");
}


Perfect Number Generator in Java

In this article I would like to share with you a sample program that I wrote in my spare time I called this program Perfect Number Generator in Java. According to Wikipedia.org a perfect number is defined as in number theory, a perfect number is a positive integer that is equal to the sum of its proper positive divisors, that is, the sum of its positive divisors excluding the number itself (also known as its aliquot sum).

What does our program will do is to ask the user to enter a number as our range from the given number our program will list down the numbers that is belong to perfect number. By the way I am using Netbeans as my text editor in this program a good text editor that is very user friendly to use and best of all it is free to download from the Internet because it is open source.

The program is very simple and easy to understand. I hope you will find my work useful in learning how to program in Java. If you have some questions please send me an email at jakerpomperada@gmail.com and jakerpomperada@yahoo.com.


People here in the Philippines can reach me at my mobile number 09173084360.


Thank you very much and Happy Programming.


Sample Program Output


Program Listing

import java.util.Scanner;  

class perfect_number
{
    public static void main(String[] args) 
    {
        Scanner input=new Scanner(System.in);
       System.out.print("\t\t    PERFECT NUMBER GENERATOR ");
       System.out.print("\n");
       System.out.print("\nKindly enter a Number ? :");
        long range_number=input.nextLong();
        System.out.println("\nThe perfect numbers from 1 and "+range_number+" are:");
        System.out.println();
        for(int b=1;b<range_number;b++)
        {
            int sum = 0;
            {
                for(int a=1;a<b;a++)
                {
                    if(b%a == 0)
                    {
                        sum+=a;
                    }
                }
                if(sum == b)
                {
                   
                    System.out.print(" "+ b + " ");
                }
            }
        }
       System.out.println("\n");
       System.out.println("\t\t END OF PROGRAM");     
       System.out.println("\n"); 
    }
       
}





Tuesday, July 7, 2015

Highest and Smaller Number in Java

One of the most interesting problem in programming is to ask the user to enter a series of number and then our program will determine which of the given number is the smallest and the highest number from the series of number by the user. Normally the data structure that we will use in this problem is array to be specific one dimensional array so to speak and then we will use for loop statement and if statement to compare each numbers and to check which of the given number is the smallest and highest.

I called this program Highest and Smallest Number in Java what the program does is to prompt or ask the user how many numbers to be accepted and to be process. After the user provide the values in our program it will compare and determine what is the smallest and the highest in a given list of values.

The program is very simple and easy to understand. I hope you will find my work useful in learning how to program in Java. If you have some questions please send me an email at jakerpomperada@gmail.com and jakerpomperada@yahoo.com.


People here in the Philippines can reach me at my mobile number 09173084360.


Thank you very much and Happy Programming.



Sample Program Output

Program Listing

// smallest_biggest_number.java
// Written By: Mr. Jake R. Pomperada, MAED-IT
// Date : July 7, 2015
// Email Address: jakerpomperada@yahoo.com
//                            jakerpomperada@gmail.com

// Problem : Write a program in Java that will check what is the highest and
//           lowest number given by the user using one dimensional array.

import java.util.Scanner;  

public class smallest_biggest_number {
    
    public static void main(String[] args) {

        Scanner input=new Scanner(System.in);
       
        int[] num= new int[10];
       
       System.out.print("\t\t    SMALLEST AND HIGHEST NUMBER ");
       System.out.print("\n\n");
       System.out.print("How many items ? : ");
       int n=input.nextInt();
       int smallest = Integer.MAX_VALUE;
       int biggest =Integer.MIN_VALUE;
      
       for(int i =0;i<n;i++) {
            int y=i+1;
            System.out.print("Enter item value no. " + y  + " value : ");
            num[i]=input.nextInt();
            if(num[i] < smallest) {

             smallest = num[i];

            }
            if (num[i] > biggest) {
                biggest = num[i];
               }

        }
       System.out.println();
       System.out.println("The Smallest number is  " +smallest + ".");
       System.out.println("The Biggest number is   " +biggest +".");
       System.out.println();
       System.out.println("\t\t END OF PROGRAM");     
       System.out.println("\n\n");
    }

}



Multiplication Table in Java

In this short article I would like to share with you a program that I wrote using Java as my programming language I called this program multiplication table. What the program does is that it will display a multiplication table on the screen very similar that is being used in elementary mathematics.  

I hope you will find my work useful in learning how to program in Java. If you have some questions please send me an email at jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

People here in the Philippines can reach me at my mobile number 09173084360.

Thank you very much and Happy Programming.



Sample Program Output

Program Listing

// multiplication_table.java
// Written By: Mr. Jake R. Pomperada, MAED-IT
// Date : July 7, 2015
// Email Address: jakerpomperada@yahoo.com
//                jakerpomperada@gmail.com

public class multiplication_table {
    public static void main(String[] args) {

        int Table_Size = 10;

      Display(Table_Size);
    }
   
    public static void Display(int Table_Size) {

        System.out.print("\t\t    MULTIPLICATION TABLE ");
        System.out.print("\n\n");
        System.out.format("      ");

        for(int i = 0; i<=Table_Size ;i++ ) {

            System.out.format("%4d",i);

        }

        System.out.println();

       System.out.println(" -------------------------------------------------");

        
        for(int i = 0 ;i<=Table_Size ;i++) {

             System.out.format("%4d |",i);

            for(int j=0;j<=Table_Size ;j++) {

                System.out.format("%4d",i*j);

            }

            System.out.println();

        }
   System.out.println("\n");
   System.out.println("\t\t END OF PROGRAM");     
   System.out.println("\n\n");
    }
}


Sunday, June 28, 2015

Reverse a Number in Java Version 2

A simple program that will ask the user to enter a number and then it will reverse the arrangement of number given by the user.The code is very simple but it uses already the concepts of object oriented programming.

I hope you will find my work  useful in a sense the logic of programming is also applied in this simple program.

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

People here in the Philippines can reach me at my mobile number 09173084360.

Thank you very much and Happy Programming.



Sample Program Output

Program Listing

import java.util.Scanner;


class reverse_number {
    public int reverse_given_number(int number)
    {
         
        int reverse = 0;
        while(number != 0){
            reverse = (reverse*10)+(number%10);
            number = number/10;
        }
        return reverse;
    }

public static void main(String args[]) {
  Scanner scan = new Scanner(System.in);
   char a;
do
    {
  // creating of value object
  
   reverse_number value = new reverse_number();
      
  System.out.println();
  System.out.println("===== REVERSE A NUMBER =====");
  System.out.println();
  System.out.print("Enter a Number :  ");
  int number_value =   scan.nextInt();
  
  System.out.println();

  System.out.print("The given number is " + number_value + 
  " it's reverse order will be " +value.reverse_given_number(number_value)+ ".");
    System.out.println("\n\n");
    System.out.print("Do you Want To Continue (Y/N) :=> ");
    a=scan.next().charAt(0);

   } while(a=='Y'|| a=='y');
          System.out.println("\n");
          System.out.println("\t ===== END OF PROGRAM ======");
         System.out.println("\n");
 }
  
   } // End of Program



Basic Math Operations in Java

A simple program that I wrote that I called Basic Math Operations in Java that will show you basic mathematical operations like addition, subtraction, multiplication and division using Java programming language.The code is very simple but it uses already the concepts of object oriented programming.

I hope you will find my work  useful in a sense the logic of programming is also applied in this simple program.

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

People here in the Philippines can reach me at my mobile number 09173084360.

Thank you very much and Happy Programming.


Sample Program Output

Program Listing

import java.util.Scanner;


class basic_math {
    public static int math_operations(int a, int b)
    {
       int sum = (a + b);
       int difference = (a-b);
       int product = (a * b);
       int quotient = (a/b);
       
      System.out.println("The sum of " + a + " and " + b + " is " + sum +".");
      System.out.println("The difference of " + a + " and " + b + " is " + difference +".");
      System.out.println("The product of " + a + " and " + b + " is " + product +".");
      System.out.println("The quotient of " + a + " and " + b + " is " + quotient +".");
      return 0;
     }

public static void main(String args[]) {
  Scanner scan = new Scanner(System.in);
   char a;
  do
    {
    System.out.println();
    System.out.println("===== BASIC MATH OPERATIONS =====");
    System.out.println();
    System.out.print("Enter two numbers : ");
    int x = scan.nextInt();
    int y = scan.nextInt();
      
     math_operations(x,y); 

    System.out.println("\n");
    System.out.print("Do you Want To Continue (Y/N) :=> ");
    a=scan.next().charAt(0);

   } while(a=='Y'|| a=='y');
     System.out.println("\n");
     System.out.println("\t ===== END OF PROGRAM ======");
     System.out.println("\n");
   }
  
  }  // End of Program


Money Bills Denomination Counter in Java

A simple program that I wrote in Java that will count how many money bills in a given amount of money. It uses % or modulo operator of Java to achieve its results.The code is very simple but it uses already the concepts of object oriented programming.

I hope you will find my work  useful in a sense the logic of programming is also applied in this simple program.

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

People here in the Philippines can reach me at my mobile number 09173084360.

Thank you very much and Happy Programming.



Sample Program Output

Program Listing

import java.util.Scanner;


class bills{
    public static int count_bills(int amount)
    {
   int solve_thousand=0,solve_five=0,solve_two=0,solve_one=0;
   int remainder_thousand=0,remainder_five=0;
   int remainder_two=0,remainder_one=0;

   solve_thousand =(amount/ 1000);
   remainder_thousand = solve_thousand % 1000;

   solve_five =(amount/ 500);
   remainder_five = solve_five % 500;

   solve_two =(amount/ 200);
   remainder_two = solve_two % 200;

   solve_one =(amount/ 100);
   remainder_one= solve_one % 200;
   
   System.out.println("\n");
   System.out.println("Number of Php 1000 Bill(s) :=> " +  remainder_thousand);
   System.out.println("Number of Php 500  Bill(s) :=> " +  remainder_five);
   System.out.println("Number of Php 200  Bill(s) :=> " +  remainder_two);
   System.out.println("Number of Php 100  Bill(s) :=> " +  remainder_one);
   return 0;
   }

public static void main(String args[]) {
  Scanner scan = new Scanner(System.in);
   char a;
  do
    {
    System.out.println();
    System.out.println("===== MONEY BILLS DENOMINATION COUNTER =====");
    System.out.println();
    System.out.print("Enter the Amount : Php  ");
    int amount = scan.nextInt();

    count_bills(amount);      
    System.out.println("\n");
    System.out.print("Do you Want To Continue (Y/N) :=> ");
    a=scan.next().charAt(0);

   } while(a=='Y'|| a=='y');
     System.out.println("\n");
     System.out.println("\t ===== END OF PROGRAM ======");
     System.out.println("\n");
   }
  
  }  // End of Program




Armstrong Checker in Java

A simple program that I wrote using Java programming language that will check if the number given by the user is an armstrong number or not. The code is very simple but it uses already the concepts of object oriented programming.

I hope you will find my work  useful in a sense the logic of programming is also applied in this simple program.

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

People here in the Philippines can reach me at my mobile number 09173084360.

Thank you very much and Happy Programming.



Sample Program Output

Program Listing

import java.util.Scanner;


class armstrong_checker {
    public int check_armstrong_number(int value)
    {
       int temp = value;
int sum = 0;
int mod = 0;
while(temp != 0) {
mod = temp % 10;
sum = sum + (mod * mod * mod);
temp = temp / 10;
}
if(sum == value) 
System.out.println("The given number " + value + " is  Armstrong Number.");
else
System.out.println("The given number " + value + " is Not an Armstrong Number.");
    return 0;
    }


public static void main(String args[]) {
  Scanner scan = new Scanner(System.in);
   char a;
do
    {
  // creating of an object
  
  armstrong_checker number = new armstrong_checker();
      
  System.out.println();
  System.out.println("===== ARMSTRONG NUMBER CHECKER =====");
  System.out.println();
  System.out.print("Enter a Number :  ");
  int number_given =   scan.nextInt();
  
  System.out.println();
  number.check_armstrong_number(number_given);
  System.out.println("\n\n");
  System.out.print("Do you Want To Continue (Y/N) :=> ");
   a=scan.next().charAt(0);

   } while(a=='Y'|| a=='y');
          System.out.println("\n");
          System.out.println("\t ===== END OF PROGRAM ======");
         System.out.println("\n");
 }
  
   } // End of Program