Hacking with an algorithm to find prime factor of a number

$./app Sign detection [1] Power of two [2] Counting No. of bits set [3] Set or clear bits without branching[4] Find maximum value[5] Finding least common multiple[6] Finding the greatest commom divisor[7] Finding if a number is an Armstrong number or not[8] Finding if a given number is prime number[9] Finding the number of twin …

How to write an algorithm to find if a number is palindrome or not

#include <stdio.h> palindrome() { int n, reverse = 0, temp; printf(“Enter a number to check if it is a palindrome or not: “); scanf(“%d”,&n); temp = n; while ( temp != 0 ) { reverse = reverse * 10; reverse = reverse + temp % 10; temp = temp/10; } if ( n == reverse …

Tinkering with an Armstrong number finding program function

$./app Sign detection [1] Power of two [2] Counting No. of bits set [3] Set or clear bits without branching[4] Find maximum value[5] Finding least common multiple[6] Finding the greatest commom divisor[7] Finding if a number is an Armstrong number or not[8] 8 Enter a positive integer: 153 153 is an Armstrong number $./app Sign …

Hacking with the program to find the greatest common factor

$./app Sign detection [1] Power of two [2] Counting No. of bits set [3] Set or clear bits without branching[4] Find maximum value[5] Finding least common multiple[6] Finding the greatest commom divisor[7] 7 Enter the two values for finding GCD: 12 6 GCD is: 6 $./app Sign detection [1] Power of two [2] Counting No. …

How to write an algorithm to find the number of bits set in a typical number ?

#include <stdio.h> cbs () { unsigned int v; /* count the number of bits set in v */ unsigned int c; /* c accumulates the total bits set in v */ printf(“Enter v”); scanf(“%u”,&v); for (c = 0; v ; c++) { v = v & (v – 1); /* clear the least significant bit …

How to write a program to connect to a PostgreSQL server ? (program may not be perfect )

#include <stdio.h> #include <stdlib.h> #include <postgresql/libpq-fe.h> int main(int argc, char **argv) { const char *conninfo; const char *serverversion; PGconn *conn; const char *paramtext = “server_version”; conninfo = “hostaddr = 127.0.0.1 dbname = test user = earl password = bigshot”; conn = PQconnectdb(conninfo); if ( PQstatus(conn) != CONNECTION_OK ) { printf(“Unable to establish connection: %s”,PQerrorMessage(conn)); return …

Tinkering with the fping command

$fping 192.168.0.1 192.168.0.1 is alive $fping 192.168.0.2 ICMP Host Unreachable from 192.168.0.103 for ICMP Echo sent to 192.168.0.2 ICMP Host Unreachable from 192.168.0.103 for ICMP Echo sent to 192.168.0.2 ICMP Host Unreachable from 192.168.0.103 for ICMP Echo sent to 192.168.0.2 ICMP Host Unreachable from 192.168.0.103 for ICMP Echo sent to 192.168.0.2 192.168.0.2 is unreachable $fping …

Hacking with httping for simple speed study

ABOUT httping httping – measure the latency and throughput of a webserver A TYPICAL SHELL SESSION [bash] $httping www.beautifulwork.org PING www.beautifulwork.org:80 (www.beautifulwork.org): connected to 80.79.116.205:80 (490 bytes), seq=0 time=809.49 ms connected to 80.79.116.205:80 (490 bytes), seq=1 time=807.21 ms connected to 80.79.116.205:80 (490 bytes), seq=2 time=788.23 ms connected to 80.79.116.205:80 (490 bytes), seq=3 time=796.85 ms ^CGot …