Friday, October 20, 2017

Linear Search in C#

Here is a sample program that I wrote using C# to demonstrate linear or sequential search. What does the program will do is to ask the user to give a number which represents an element and then our program will search the given number or element from a list of values stored in our one dimensional array if the given number is there or not.

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

linear.cs

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

namespace ConsoleApplication1
{
    class Linear_Search
    {
        static void Main(string[] args)
        {

            int flag = 0;

            int[] arr = { 5,6,7,8,9,10,11,12,13,14,15}; 

            int num=0;

            Console.WriteLine("\tLinear Search in C# ");
            Console.WriteLine("\n");
            Console.WriteLine("Created By Mr. Jake R. Pomperada");
            Console.WriteLine("\n\n");
            Console.Write("Enter element to be search : ");
            num = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("\n\n");

          

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

                if (arr[i] == num)
                {

                    Console.WriteLine(num + " element is found in the list");
                    Console.WriteLine("\n\n");

                    flag = 1;

                }

                else
                {

                    Console.WriteLine("Searching element form the list.");
                    Console.WriteLine("\n\n");

                }

                if (flag == 1) break;

            }

            if (flag == 0)
            {

                Console.WriteLine("\n\n");
                Console.WriteLine(num + " Not Found in the list.");

            }

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




Array Demonstration in C#

A very simple program that I wrote using C# to demonstration array as our data structure.  The code is very short and easy to understand.

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


array_demo.cs


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

namespace array_demo
{
    class array_demo
    {
        static void Main(string[] args)
        {
            int[] values = new int[12]; /* values is an array of 5 integers */
            int a = 0, b = 0;

            /* initialize elements of array values*/
            for (a = 0; a < 12; a++)
            {
                values[a] = a + 100;
            }

            Console.Write("\n\n");
            Console.Write("\t      Array Demonstration Program ");
            Console.Write("\n\n");
            /* output each array element's value */
            for (b = 0; b < 12; b++)
            {
                Console.WriteLine("\t\t Element[{0}] = {1}", b, values[b]);
            }
            Console.Write("\n\n");
            Console.Write("\t Thank You For Using This Software.");
            Console.ReadKey();
        }
    }

}

Two Dimensional Arrays in C#

A very simple program that I wrote using C# as my programming language to show and demonstrate the concepts of two dimensional array.


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

two_dimensional.cs


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

namespace two_dimensional
{
    class two_dimensional
    {
        static void Main(string[] args)
        {
            int[,] values = 
            { 
                {10, 20, 30, 40}, // row 0 values 
                {50, 60, 70, 80}, // row 1 values 
                {90, 100, 110, 120}, // row 2 values 
            };
            Console.Write("\n\n");
            Console.Write("\t  Two Dimensional Array Demonstration Program ");
            Console.Write("\n\n\n");
            for (int row = 0; row < values.GetLength(0); row++)
            {
                for (int col = 0; col < values.GetLength(1); col++)
                {
                    Console.Write("  {0}  " ,values[row, col]);
                }
            }
            Console.Write("\n\n\n");
            Console.Write("\t    Thank You For Using This Software.");
            Console.ReadKey();
        }
    }

}

Calculator in C#

In this article I would like to share with you a simple program that uses methods in C# I called this program calculator in C# what does the program will do is to ask the user to give two values and then it will compute the sum, product, difference and quotient of the given two numbers from our user.

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

calculator.cs


class calculator
    {
        double  sum(double n1, double  n2)
        {
            return n1 + n2;
        }
        double  subtract(double n1, double  n2)
        {
            return n1 - n2;
        }
        double multiply(double  n1, double n2)
        {
            return n1 * n2;
        }
        double division(double  n1, double n2)
        {
            return n1 / n2;
        }
        static void Main(string[] args)
        {
            calculator c = new calculator();
            double input1, input2;
    
       Console.WriteLine("Calculator in C#");
Console.Write("\n\n");
            Console.WriteLine("Give first value : ");
            input1 = Convert.ToDouble(Console.ReadLine());
            Console.WriteLine("Give second value : ");
            input2 = Convert.ToDouble(Console.ReadLine());
            double x = c.sum(input1, input2);
            double y = c.multiply(input1, input2);
            double z = c.division(input1, input2);
            double w = c.subtract(input1, input2);

               Console.WriteLine("subtraction {0}",w);
               Console.WriteLine("sum {0}", x);
               Console.WriteLine("multiply {0}", y);
               Console.WriteLine("division {0}", z);
   
Console.Write("\n\n");
               Console.Write("Thank You For Using This Software.");
               Console.Write("\n\n");
        }   
    }
}


Reverse a Number in C#

Here is a very simple program that I wrote before as a simple programming activity in my upcoming book on C# programming. I will ask the user to give a number and then our program will reverse the arrangement of the given number by our user.

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

reverse.cs


using System;

namespace ReverseNo
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Enter a No. to reverse");
            int Number = int.Parse(Console.ReadLine());
            int Reverse = 0;
            while(Number>0)
            {
                int remainder = Number % 10;
                Reverse = (Reverse * 10) + remainder;
                Number = Number / 10;
            }
            Console.WriteLine("Reverse No. is {0}",Reverse);
            Console.ReadLine();
        }
    }
}

Legal Age Checker Using Switch Statement in C#

I wrote this simple program in C# as an example for my upcoming book on C# programming what does the program will do is to check if the given age of the user is already an adult or not using switch statement in C#. The code is very easy to understand and use I hope you will find my work useful.

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

legal.cs

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

/* Legal Age Checker                                */
/* Author : Mr. Jake R. Pomperada, MAED-IT          */
/* Date   : November 20, 2016    Sunday 10:25 AM    */
/* Tool   : C#                                      */

namespace legal_age
{
    class legal_age
    {
        static void Main(string[] args)
        {
            string reply;
            int n = 0;
            int age = 0;

            do
            {
                Console.Clear();
                Console.Write("Legal Age Checker ");
                Console.Write("\n\n");
                Console.Write("Enter Your Age    : ");
                age = Convert.ToInt32(Console.ReadLine());

                switch(age) {
                    case 1: case 2: case 3:  case 4: case 5: case 6:
                    case 7: case 8: case 9:  case 10: case 11: case 12:
                    case 13: case 14:  case 15: case 16: case 17:
                    Console.Write("\n\n");
                    Console.WriteLine("At the age {0} you are still a Minor.", age);
                    break;
                    default:
                    Console.Write("\n\n");
                    Console.WriteLine("At the age {0} you are already an Adult.", age);
                   break;
                  }
                Console.Write("\n\n");
                Console.Write("Do You Want To Continue? Y/N : ");
                reply = Console.ReadLine();

                if (reply == "y" || reply == "Y")
                {
                    continue;
                }
                else if (reply == "n" || reply == "N")
                {
                    Console.Write("\n\n");
                    Console.Write("Thank You For Using This Software.");
                    Console.Write("\n\n");
                    break;
                }

            } while (n == 0);
            Console.ReadLine();
        }
    }
}

Divisible Number in C#

A simple program that I wrote using C# as my programming language to check if the given number is divisible or not.  I am using Mono as my C# compiler that is free to download over the Internet.

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

divisible.cs

using System;

namespace divisible
{
    class divisible
    {
        static void Main(string[] args)
        {
            int num=0;
Console.Clear();
Console.Write("\n\n");
Console.Write("Checking Number Divisibility");
Console.Write("\n\n");
            Console.Write("Enter Any Number :  ");
            num=Convert.ToInt32(Console.ReadLine());

if((num%5 == 0) && (num%11 == 0) )
{
Console.Write("\n\n");
Console.Write("Number is divisible by 5 and 11.");
}
    else
{
Console.Write("\n\n");
Console.Write("Number is not divisible by 5 and 11.");
}
      Console.Write("\n\n");
Console.Write("End of Program");
Console.Write("\n\n");
            Console.ReadLine();
        }
    }

}




Legal Age Checker in C#

I wrote this simple program in C# as an example for my upcoming book on C# programming what does the program will do is to check if the given age of the user is already an adult or not. The code is very easy to understand and use I hope you will find my work useful.

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

age.cs

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

namespace legal_age
{
    class legal_age
    {
        static void Main(string[] args)
        {
            string reply;
            int n = 0;
            int age = 0;
          
            do
            {
                Console.Clear();
                Console.Write("Legal Age Checker ");
                Console.Write("\n\n");
                Console.Write("Enter Your Age    : ");
                age = Convert.ToInt32(Console.ReadLine());

                if (age >= 18)
                {
                    Console.Write("\n\n");
                    Console.WriteLine("At the age {0} you are already an Adult.",age);
                }
                else
                {
                    Console.Write("\n\n");
                    Console.WriteLine("At the age {0} you are still a Minor.",age);
                }
                Console.Write("\n\n");
                Console.Write("Do You Want To Continue? Y/N : ");
                reply = Console.ReadLine();

                if (reply == "y" || reply == "Y")
                {
                    continue;
                }
                else if (reply == "n" || reply == "N")
                {
                    Console.Write("\n\n");
                    Console.Write("Thank You For Using This Software.");
                    Console.Write("\n\n");
                    break;
                }

            } while (n == 0);
            Console.ReadLine();
        }
    }
}



Monday, October 16, 2017

Factors of a Number in C++

A very simple program that I wrote using C++ that will ask the user to give a number and then our program will display the factors of the given number. The code is very short and easy to understand. I hope you will find my work useful. I am using CodeBlocks as my text editor and Dev C++ as my C++ compiler in writing this program. Thank you.

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

factors.cpp


#include <iostream>

using namespace std;

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

    cout << "=================================================";
    cout << "\n\n";
    cout << "\t Factors of a Number in C++";
    cout << "\n\n";
    cout << "======= Created By Jake Pomperada, MAED-IT =======";
    cout << "\n\n";
    cout << "Give a number :";
    cin >> value_number;

    cout << "\n\n";
    cout << "The factors of " << value_number << ".";

    cout << "\n\n";


    for(a=1; a <= value_number; a++)
    {
        if (value_number % a == 0)
        {
            cout << " " << a << " ";
        }
    }
   cout << "\n\n";
   cout << "End of Program";
   cout << "\n\n";

}