Menu BAR

FEEL FREE TO ASK ANY PROGRAM and please mention any error if you find it

30 Dec 2023

What is an Algorithm?

An algroithm definition is as simple as a set of step-by-step procedures or a list of rules to follow for completing a specific task or solving a particular problem.

Example of an algorithm for baking a cake ->

1) Gather all the ingredients
2) Pre-heat the oven
3) Measure out the ingredients
4) Mix together to make the batter
5) Put the butter into the pan
6) Pour the batter into the pan
7) Put the pan in the oven
8) Set a timer
9) When the timer goes off, take the pan out of the over
10) Eat the cat and ENJOY!

29 Dec 2023

Algorithm to Multiply two numbers

function multiplyTwoNumbers(a, b):
result = 0 // Initialize the result to zero

// Iterate through each digit of the second number (y)
while y > 0:
// If the rightmost digit of y is 1, add the current value of x to the result
if y is odd:
result = result + x

// Shift both x and y to the right
x = x << 1

// Multiply x by 2 (left shift)
y = y >> 1

// Divide y by 2 (right shift)
return result

28 Dec 2023

Find Maximum Value Input: An array of numbers

Find Maximum Value Input: An array of numbers, arr

1. If arr is empty, return an error or a special value indicating no maximum.

2. Set max_value to the first element of arr (arr[0]).

3. For each element num in arr starting from the second element (index 1):
a. If num is greater than max_value, update max_value to num.

4. Return max_value as the maximum value in the array. Example: arr = [5, 2, 9, 1, 5, 6]
Result: The maximum value is 9.

Algorithm - Binary Search

// Write an algorithm to do a binary search in an array

- Find the midpoint of the sorted array
- Compare the midpoint to the value of interest
- If the midpoint is larger than the value, perform binary search on right half of the array
- If the midpoint is smaller than the value, perform binary search on left half of the array
- Repeat these steps until the midpoint value is equal to the value of interest or we know the value is not in the array

Node js to create the mysql Database

var mysql = require('mysql');
var con = mysql.createConnection({ host: "localhost", user: "admin", password: "admin" });
con.connect(function(err) {
    if (err)
        throw err;
    console.log("Connected!");
    con.query("CREATE DATABASE cprogramcodes", function (err, result) {
         if (err)
            throw err;
        console.log("Database created");
     });
});



PLSQL procedure to find the minimum of the two number

DECLARE a number; b number; c number; 

PROCEDURE findMinimum(x IN number, y IN number, z OUT number) IS
BEGIN
    IF x < y
         THEN z:= x;
    ELSE
         z:= y;
    END IF;
END; 

BEGIN
    a:= 12;
    b:= 13;
    findMinimum(a, b, c);
    dbms_output.put_line(' Minimum of (12, 13) : ' || c);
END;
/



PLSQL Procedure to print HELLO WORLD!!

CREATE OR REPLACE PROCEDURE beginner
AS 
 BEGIN 
         dbms_output.put_line('HELLO WORLD!!'); 
 END; 
/


// to execute 
EXECUTE beginner;

21 Dec 2023

Node js program to write HELLO WORLD

 // node js code to create a server and write HELLO WORLD!

var http = require ('http');

http.createServer (function (req,res) => {
res.writeHead(200, {'Content-Type': 'text/html'});
res.end('HELLO WORLD!');})
.listen(8080);


// Copy and paste the above code into a file and name it helloworld.js
// Now to run it, open the command prompt and go to the file location
// Execute the first command - >
//                                                 npm i http
//Execute the second command ->
//                                                node helloworld.js
// now open browser and copy and paste the link in the URL - http://localhost:8080