Sunday, July 17, 2016

Product of Two Numbers in Rust

A simple program that I wrote using Rust programming language that will ask the user to give two numbers and then our program will find its product. The code is very simple and easy to understand.

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

My mobile number here in the Philippines is 09173084360.




Sample Program Output


Program Listing

product_two.rs

// Product of Two Numbers in Rust Programming language.
// Written By: Mr. Jake R. Pomperada, MAED-IT
// July 17, 2016

use std::io::{self, Write};
use std::fmt::Display;
use std::process;

fn main() {
       println!("\n");
       println!("\tProduct of Two Numbers in Rust");
       println!("\n");

    let value1: i32 = grab_input("Enter First Number ")
        .unwrap_or_else(|e| exit_err(&e, e.raw_os_error().unwrap_or(-1)))
        .trim()
        .parse()
        .unwrap_or_else(|e| exit_err(&e, 2));

    let value2: i32 = grab_input("Enter Second Number ")
        .unwrap_or_else(|e| exit_err(&e, e.raw_os_error().unwrap_or(-1)))
        .trim()
        .parse()
        .unwrap_or_else(|e| exit_err(&e, 2));


    let product = value1 * value2;

    println!("\n"); 
    println!("===== DISPLAY RESULTS =====");
    println!("\n"); 
    println!("The product of {} and {} is {}. ",value1,value2,product);
    println!("\n"); 
    println!("End of Program");
}

fn grab_input(msg: &str) -> io::Result<String> {
    let mut buf = String::new();
    print!("{}: ", msg);
    try!(io::stdout().flush());

    try!(io::stdin().read_line(&mut buf));
    Ok(buf)
}

fn exit_err<T: Display>(msg: T, code: i32) -> ! {
    let _ = writeln!(&mut io::stderr(), "Error: {}", msg);
    process::exit(code)
}




Simple Calculator in Rust

A  simple math calculator I wrote using Rust as my programming language what does the program will do is to ask the user to give two numbers and then our program will compute for the sum, product, different and quotient of the given  numbers. I hope you will find my work useful in learning rust programming.

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

My mobile number here in the Philippines is 09173084360.



Sample Program Output


Program Listing

calc.rs

// Simple Calculator in Rust Programming language.
// Written By: Mr. Jake R. Pomperada, MAED-IT
// July 17, 2016

use std::io::{self, Write};
use std::fmt::Display;
use std::process;
 
fn main() {
       println!("\n");
       println!("\tSimple Calculator in Rust");
       println!("\n");
 
    let value1: i32 = grab_input("Enter First Number ")
        .unwrap_or_else(|e| exit_err(&e, e.raw_os_error().unwrap_or(-1)))
        .trim()
        .parse()
        .unwrap_or_else(|e| exit_err(&e, 2));

    let value2: i32 = grab_input("Enter Second Number ")
        .unwrap_or_else(|e| exit_err(&e, e.raw_os_error().unwrap_or(-1)))
        .trim()
        .parse()
        .unwrap_or_else(|e| exit_err(&e, 2));
 

    let sum = value1 + value2;

    let subtract = value1 - value2;

    let product = value1 * value2;

    let quotient = value1 / value2;

    println!("\n"); 
    println!("===== DISPLAY RESULTS =====");
    println!("\n"); 
    println!("The sum of {} and {} is {}. ",value1,value2,sum);
    println!("\n"); 
    println!("The difference between {} and {} is {}. ",value1,value2,subtract);
    println!("\n"); 
    println!("The product of {} and {} is {}. ",value1,value2,product);
    println!("\n"); 
    println!("The quotient of {} and {} is {}. ",value1,value2,quotient); 
    println!("\n");
    println!("End of Program");
}
 
fn grab_input(msg: &str) -> io::Result<String> {
    let mut buf = String::new();
    print!("{}: ", msg);
    try!(io::stdout().flush());
 
    try!(io::stdin().read_line(&mut buf));
    Ok(buf)
}
 
fn exit_err<T: Display>(msg: T, code: i32) -> ! {
    let _ = writeln!(&mut io::stderr(), "Error: {}", msg);
    process::exit(code)
}

Factorial of Number in Rust

This sample program will ask the user to give a number and then it will compute its factorial equivalent based on the number being provided by the user using Rust as my programming language.

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

My mobile number here in the Philippines is 09173084360.



Sample Program Output


Program Listing

factorial.rs

// Factorial of Numbers in Rust Programming language.
// Written By: Mr. Jake R. Pomperada, MAED-IT
// July 17, 2016

use std::io::{self, Write};
use std::fmt::Display;
use std::process;

fn factorial (n: i32) -> i32 {
    match n {
        0 => 1,
        _ => n * factorial(n-1)
    }
}

fn main() {
       println!("\n");
       println!("\tFactorial in Rust");
       println!("\n");

    let value: i32 = grab_input("Enter a Number ")
        .unwrap_or_else(|e| exit_err(&e, e.raw_os_error().unwrap_or(-1)))
        .trim()
        .parse()
        .unwrap_or_else(|e| exit_err(&e, 2));

    println!("\n"); 
    println!("The factorial values of {} is {}.",value, factorial(value));
    println!("\n"); 
    println!("End of Program");
}

fn grab_input(msg: &str) -> io::Result<String> {
    let mut buf = String::new();
    print!("{}: ", msg);
    try!(io::stdout().flush());

    try!(io::stdin().read_line(&mut buf));
    Ok(buf)
}

fn exit_err<T: Display>(msg: T, code: i32) -> ! {
    let _ = writeln!(&mut io::stderr(), "Error: {}", msg);
    process::exit(code)
}

Leap Year Checker in Rust

This sample program that I wrote using Rust as my programming language will ask the user to give a year and then our program will determine whether the given year by our user is leap year or not a leap year.

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

My mobile number here in the Philippines is 09173084360.



Sample Program Output


Program Listing

leap_year.rs

// Leap Year Checker in Rust Programming language.
// Written By: Mr. Jake R. Pomperada, MAED-IT
// July 17, 2016

use std::io::{self, Write};
use std::fmt::Display;
use std::process;

fn main() {
       println!("\n");
       println!("\tLeap Year Checker in Rust");
       println!("\n");

    let year: i32 = grab_input("Enter a Year ")
        .unwrap_or_else(|e| exit_err(&e, e.raw_os_error().unwrap_or(-1)))
        .trim()
        .parse()
        .unwrap_or_else(|e| exit_err(&e, 2));

   if year % 400 == 0 {
    println!("\n"); 
    println!("The year {} is a leap year.",year);
    }
 else if year % 100 == 0 {
    println!("\n"); 
    println!("The year {} is a leap year.",year);
   }
 else if year % 4 == 0 {
    println!("\n"); 
    println!("The year {} is a leap year.",year);
   }
   else {
    println!("\n"); 
    println!("The year {} is not a leap year.",year);
   }
  
  
    println!("\n"); 
    println!("End of Program");
}

fn grab_input(msg: &str) -> io::Result<String> {
    let mut buf = String::new();
    print!("{}: ", msg);
    try!(io::stdout().flush());

    try!(io::stdin().read_line(&mut buf));
    Ok(buf)
}

fn exit_err<T: Display>(msg: T, code: i32) -> ! {
    let _ = writeln!(&mut io::stderr(), "Error: {}", msg);
    process::exit(code)
}



Hello World in Rust

In this article I would like to share with you a very classic sample program hello world using Rust as our programming language. To give you some idea Rust programming language was developed and promote by Mozilla Foundation it is a system programming language similar to C and C++ programming languages and open source. Learning how to program in Rust is not difficult but easy to understand once you have a basic understanding on C or C++ programming.

This sample program will display hello world and welcome to rust programming message on the screen. I hope this program will give you a first hand experience how to start write a program in Rust programming language.

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

My mobile number here in the Philippines is 09173084360.




Sample Program Output


Program Listing

fn main() {
  println!("\n");
  println!("Hello, world!");
  println!("\n");
  println!("\t Welcome To Rust Programming");
  }



Odd and Even Number Checker in Rust

Hello friends in this article I would like to share with you how to write a program to check if the given number by the user is odd or even number  using Rust Programming language. Yesterday I am attending a lecture in Mozilla Philippines office here in Makati City, Philippines. The talk is given by Sir Bob Reyes a Mozilla representative here in the Philippines he is discussing the Rust programming language I found his lecture interesting because Rust is designed for systems programming and best of all it is open source.

Rust is a programming language that is developed by Mozilla foundation the creator of Mozilla Firefox web browser one of the most popular and secure web browser in the world. I hope you will give a try to learn Rust.

In this program it will ask the user to give a number and then our program will determine whether the given number is odd and even.


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

My mobile number here in the Philippines is 09173084360.



Sample Program Output


Program Listing

odd_even.rs

// Odd and Even Number Checker in Rust Programming language.
// Written By: Mr. Jake R. Pomperada, MAED-IT
// July 17, 2016

use std::io::{self, Write};
use std::fmt::Display;
use std::process;

fn main() {
       println!("\n");
       println!("\tOdd and Even Number Checker in Rust");
       println!("\n");

    let value: i32 = grab_input("Enter a Number ")
        .unwrap_or_else(|e| exit_err(&e, e.raw_os_error().unwrap_or(-1)))
        .trim()
        .parse()
        .unwrap_or_else(|e| exit_err(&e, 2));

   if value % 2 == 0 {
    println!("\n"); 
    println!("The number {} is an EVEN number.",value);
} else {
    println!("\n");
    println!("The number {} is an ODD number.",value);
   }

    println!("\n"); 
    println!("End of Program");
}

fn grab_input(msg: &str) -> io::Result<String> {
    let mut buf = String::new();
    print!("{}: ", msg);
    try!(io::stdout().flush());

    try!(io::stdin().read_line(&mut buf));
    Ok(buf)
}

fn exit_err<T: Display>(msg: T, code: i32) -> ! {
    let _ = writeln!(&mut io::stderr(), "Error: {}", msg);
    process::exit(code)
}





Addition of Two Numbers in Rust

Hello friends in this article I would like to share with you how to write a program to find the sum of two numbers  using Rust Programming language. Yesterday I am attending a lecture in Mozilla Philippines office here in Makati City, Philippines. The talk is given by Sir Bob Reyes a Mozilla representative here in the Philippines he is discussing the Rust programming language I found his lecture interesting because Rust is designed for systems programming and best of all it is open source.

Rust is a programming language that is developed by Mozilla foundation the creator of Mozilla Firefox web browser one of the most popular and secure web browser in the world. I hope you will give a try to learn Rust.

In this program it will ask the user to give to two numbers and then our program will find the sum of the two numbers provided by the user.

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


My mobile number here in the Philippines is 09173084360.



Sample Program Output



Program Listing

add.rs

// Addition of Two Numbers in Rust Programming language.
// Written By: Mr. Jake R. Pomperada, MAED-IT
// July 17, 2016

use std::io::{self, Write};
use std::fmt::Display;
use std::process;

fn main() {
       println!("\n");
       println!("\tAddition of Two Numbers in Rust");
       println!("\n");

    let value1: i32 = grab_input("Enter First Number ")
        .unwrap_or_else(|e| exit_err(&e, e.raw_os_error().unwrap_or(-1)))
        .trim()
        .parse()
        .unwrap_or_else(|e| exit_err(&e, 2));

    let value2: i32 = grab_input("Enter Second Number ")
        .unwrap_or_else(|e| exit_err(&e, e.raw_os_error().unwrap_or(-1)))
        .trim()
        .parse()
        .unwrap_or_else(|e| exit_err(&e, 2));


    let sum = value1 + value2;
     
    println!("\n"); 
    println!("The sum of {} and {} is {}. ",value1,value2,sum);
    println!("\n"); 
    println!("End of Program");
}

fn grab_input(msg: &str) -> io::Result<String> {
    let mut buf = String::new();
    print!("{}: ", msg);
    try!(io::stdout().flush());

    try!(io::stdin().read_line(&mut buf));
    Ok(buf)
}

fn exit_err<T: Display>(msg: T, code: i32) -> ! {
    let _ = writeln!(&mut io::stderr(), "Error: {}", msg);
    process::exit(code)
}




Friday, July 15, 2016

Addition of Five Numbers in AngularJS

In this article I would like to share with you a sample program that I wrote using AngularJS one of the most popular javascript framework today. What does the program will do is to ask the user to give five numbers and then it will find the sum of the five numbers that is being provided by the user. What is good about this program is that it uses buttons to add the sum of numbers and clear button to clear the content of the text box. I hope you will find my work useful.

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

My mobile number here in the Philippines is 09173084360.



Sample Program Output


Program Listing

<html>
<head> 
<title> Avergage of Five Numbers in AngularJS </title>
</head>
<style>
p,h3 {
   color:blue;
     display: inline-block;
    float: left;
    clear: left;
    width: 380px;
    text-align: left;
   font-family: "arial";
   font-style: bold;
   size: 16;
  };
  
  
 </style>
<script type="text/javascript" src="angular.js"></script>
<body bgcolor="lightgreen">
<script>
var app = angular.module('myApp', []);

app.controller('MainCtrl', function($scope) {
$scope.add=function(a,b,c,d,e)
{
  $scope.result=parseInt(a)+parseInt(b)+parseInt(c)+parseInt(d)+parseInt(e);
}

$scope.clear_all=function()
{
  $scope.a = null;
   $scope.b = null;
   $scope.c = null;
   $scope.d = null;
   $scope.e = null;
    
}


});

</script>
<br><br>
<h3>Addition of Five Numbers in AngularJS</h3>
<div ng-app="myApp">
<div ng-controller="MainCtrl">
    <p>Enter a Value in Item No. 1 :
        <input type="text" ng-model="a" placeholder="enter a number" autofocus size="15"/>
    </p><br>
    
   <p>Enter a Value in Item No. 2 :
        <input type="text" ng-model="b" placeholder="enter a number" size="15"/>
    </p><br>
<p>Enter a Value in Item No. 3 :
        <input type="text" ng-model="c" placeholder="enter a number" size="15"/>
    </p><br>
    
    <p>Enter a Value in Item No. 4 :
        <input type="text" ng-model="d" placeholder="enter a number" size="15"/>
    </p><br>
<p>Enter a Value in Item No. 5 :
        <input type="text" ng-model="e" placeholder="enter a number" size="15"/>
    </p><br> 
      <br>
<br><br>
<br><br>
     <p><input type="button" ng-click="add(a,b,c,d,e)" value="ADD">
&nbsp;
 <input type="button" ng-click="clear_all(this)" value="CLEAR"></p>
<br><br>
<p> Total Sum is  {{result}}. </p>
<div>
</div>
</html>




Sunday, July 10, 2016

Sum of Three Numbers in Java

A simple program that I wrote in Java that will ask the user to give three integer numbers and then our program will find the total sum of three numbers based of the given values by our user. 

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

My mobile number here in the Philippines is 09173084360.



Sample Program Output


Program Listing


sum_three.java


package hello;


import java.util.Scanner;
public class sum_three {
 public static void main(String args[]){
 
 Scanner input = new Scanner(System.in);
    
       int sum=0;
       int a=0,b=0,c=0;
    
       System.out.println("Sum of Three Numbers in Java");
       System.out.println();
       System.out.print("Enter First Number : ");
       a = input.nextInt();
       System.out.print("Enter Second Number : ");
       b = input.nextInt(); 
       System.out.print("Enter Third Number : ");
       c = input.nextInt(); 
     
       sum = (a+b+c);
       
       System.out.println();
       System.out.println("The sum of " +a + "," + b + " and " + 
           c + " is " + sum + ".");
       System.out.println();
       System.out.println("\t End of Program");
 
 }
 
}