28 Dec 2023
Algorithm - Binary Search
- 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!!
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
20 Nov 2022
C++ Program to call the function
#include<conio.h>
class first
{
public:
void my()
{
cout<<"Welcome to C++";
}
};
void main()
{
first a;
a.my();
getch();
}
===OUTPUT===
Welcome to C++
16 Nov 2022
Java Program to print an integer entered by user
import java.util.Scanner;
public class PrintInteger {
public static void main (String[] args){
Scanner reader = new Scanner (System.in);
int number = reader.nextInt ();
}
15 Nov 2022
Node JS program to connect to SQL table and use WHERE clause
## Node JS program to connect to SQL table and use WHERE clause ##
var mysql = require ('mysql');
// create a connection
var con = mysql.createConnection({
host: "localhost",
user: "admin",
password: "admin",
database: "dummy"
});
con.connect(function(err)){
if (err) throw err;
con.query("Select * from student where age>15", function (err, result, fields) {
if (err) throw err;
console.log (" Result is: ", result);
});
});
14 Nov 2022
Node JS program to delete a text file
## Node JS program to delete a text file ##
var fs = require ('fs');
fs.unlink ('file.txt', function (err){
if (err) throw err;
console.log (' File deleted successfully!! ');
});
===OUTPUT===
Run the program using the node command:
$ node deleteFile.js
File deleted successfully!!