BeautifulWork Project
http://www.beautifulwork.org
LEARNING PROCESSSun, 31 Aug 2014 17:26:00 +0000en-UShourly1http://wordpress.org/?v=3.6.1Hacking with debian netselect-apt command
http://www.beautifulwork.org/2014/08/31/hacking-with-debian-netselect-apt-command/?utm_source=rss&utm_medium=rss&utm_campaign=hacking-with-debian-netselect-apt-command
http://www.beautifulwork.org/2014/08/31/hacking-with-debian-netselect-apt-command/#commentsSun, 31 Aug 2014 17:26:00 +0000adminhttp://www.beautifulwork.org/?p=15929] 3,50,858 110KB/s in 3.1s 2014-08-31 23:00:11 (110 KB/s) - ‘/tmp/netselect-apt.Pjgwxz’ saved […]]]>
$sudo netselect-apt -t 2 -c IN
Using distribution stable.
Retrieving the list of mirrors from www.debian.org...
--2014-08-31 23:00:07-- http://www.debian.org/mirror/mirrors_full
Resolving www.debian.org (www.debian.org)... 140.211.15.34, 128.31.0.51
Connecting to www.debian.org (www.debian.org)|140.211.15.34|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 350858 (343K) [text/html]
Saving to: ‘/tmp/netselect-apt.Pjgwxz’
100%[====================================================================================>] 3,50,858 110KB/s in 3.1s
2014-08-31 23:00:11 (110 KB/s) - ‘/tmp/netselect-apt.Pjgwxz’ saved [350858/350858]
Choosing a main Debian mirror using netselect.
(will filter only for mirrors in country IN)
Running netselect to choose 2 out of 4 addresses.
...........
Only found 1 hosts out of 2 requested.
The fastest 2 servers seem to be:
http://debian.mirror.net.in/debian/
Of the hosts tested we choose the fastest valid for HTTP:
http://debian.mirror.net.in/debian/
Writing sources.list.
sources.list exists, moving to sources.list.1409506243
Done.
$
]]>http://www.beautifulwork.org/2014/08/31/hacking-with-debian-netselect-apt-command/feed/0How to write an algorithm to find factorial of a given number ?
http://www.beautifulwork.org/2014/08/21/how-to-write-an-algorithm-to-find-factorial-of-a-number/?utm_source=rss&utm_medium=rss&utm_campaign=how-to-write-an-algorithm-to-find-factorial-of-a-number
http://www.beautifulwork.org/2014/08/21/how-to-write-an-algorithm-to-find-factorial-of-a-number/#commentsThu, 21 Aug 2014 20:52:36 +0000adminhttp://www.beautifulwork.org/?p=15925
#include <stdio.h>
factorial()
{
int p = 1;
int i = 1;
int n;
printf("Enter a Number greater than 0 \n");
scanf("%d",&n);
while ( i <= n)
{
p = p * i;
i = i + 1;
}
printf("Factorial of the input is %d \n",p);
}
]]>http://www.beautifulwork.org/2014/08/21/how-to-write-an-algorithm-to-find-factorial-of-a-number/feed/0Hacking with an algorithm to find prime factor of a number
http://www.beautifulwork.org/2014/08/19/hacking-with-an-algorithm-to-find-prime-factor-of-a-number/?utm_source=rss&utm_medium=rss&utm_campaign=hacking-with-an-algorithm-to-find-prime-factor-of-a-number
http://www.beautifulwork.org/2014/08/19/hacking-with-an-algorithm-to-find-prime-factor-of-a-number/#commentsTue, 19 Aug 2014 19:09:49 +0000adminhttp://www.beautifulwork.org/?p=15923
$./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 prime numbers[10]
Finding if a number is palindrome or not[11]
Finding prime factor of a number[12]
12
Enter a number: 36
2 is a prime factor
3 is a prime 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]
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 prime numbers[10]
Finding if a number is palindrome or not[11]
Finding prime factor of a number[12]
12
Enter a number: 76
2 is a prime factor
19 is a prime factor
$bc
bc 1.06.95
Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'.
76/19
4
]]>http://www.beautifulwork.org/2014/08/19/hacking-with-an-algorithm-to-find-prime-factor-of-a-number/feed/0How to write an algorithm to find if a number is palindrome or not
http://www.beautifulwork.org/2014/08/19/how-to-write-a-algorithm-to-find-if-a-number-is-palindrome-or-not/?utm_source=rss&utm_medium=rss&utm_campaign=how-to-write-a-algorithm-to-find-if-a-number-is-palindrome-or-not
http://www.beautifulwork.org/2014/08/19/how-to-write-a-algorithm-to-find-if-a-number-is-palindrome-or-not/#commentsTue, 19 Aug 2014 17:37:50 +0000adminhttp://www.beautifulwork.org/?p=15920
#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 )
printf("%d is a palindrome number \n",n);
else
printf("%d is not a palindrome number \n",n);
}
]]>http://www.beautifulwork.org/2014/08/19/how-to-write-a-algorithm-to-find-if-a-number-is-palindrome-or-not/feed/0Tinkering with an Armstrong number finding program function
http://www.beautifulwork.org/2014/08/12/tinkering-with-an-armstrong-number-finding-program-function/?utm_source=rss&utm_medium=rss&utm_campaign=tinkering-with-an-armstrong-number-finding-program-function
http://www.beautifulwork.org/2014/08/12/tinkering-with-an-armstrong-number-finding-program-function/#commentsTue, 12 Aug 2014 14:42:34 +0000adminhttp://www.beautifulwork.org/?p=15917
$./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 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: 154
154 is not an Armstrong 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]
8
Enter a positive integer: 1
1 is an Armstrong number
$
]]>http://www.beautifulwork.org/2014/08/12/tinkering-with-an-armstrong-number-finding-program-function/feed/0Hacking with the program to find the greatest common factor
http://www.beautifulwork.org/2014/08/07/hacking-with-the-program-to-find-the-greatest-common-factor/?utm_source=rss&utm_medium=rss&utm_campaign=hacking-with-the-program-to-find-the-greatest-common-factor
http://www.beautifulwork.org/2014/08/07/hacking-with-the-program-to-find-the-greatest-common-factor/#commentsThu, 07 Aug 2014 15:57:54 +0000adminhttp://www.beautifulwork.org/?p=15915
$./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. 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: 5 12
GCD is: 1
$./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: 20 25
GCD is: 5
$./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 8
GCD is: 4
$./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: 32 235
GCD is: 1
$
]]>http://www.beautifulwork.org/2014/08/07/hacking-with-the-program-to-find-the-greatest-common-factor/feed/0How to write an algorithm to find the number of bits set in a typical number ?
http://www.beautifulwork.org/2014/07/30/how-to-write-an-algorithm-to-find-the-number-of-bits-set-in-a-typical-number/?utm_source=rss&utm_medium=rss&utm_campaign=how-to-write-an-algorithm-to-find-the-number-of-bits-set-in-a-typical-number
http://www.beautifulwork.org/2014/07/30/how-to-write-an-algorithm-to-find-the-number-of-bits-set-in-a-typical-number/#commentsWed, 30 Jul 2014 15:39:30 +0000adminhttp://www.beautifulwork.org/?p=15912
#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 set */
}
printf("The number of bits set in v is %u \n",c);
}
]]>http://www.beautifulwork.org/2014/07/30/how-to-write-an-algorithm-to-find-the-number-of-bits-set-in-a-typical-number/feed/0How to write an algorithm to detect if two integers have opposite signs ?
http://www.beautifulwork.org/2014/07/25/how-to-write-an-algorithm-to-detect-if-two-integers-have-opposite-signs/?utm_source=rss&utm_medium=rss&utm_campaign=how-to-write-an-algorithm-to-detect-if-two-integers-have-opposite-signs
http://www.beautifulwork.org/2014/07/25/how-to-write-an-algorithm-to-detect-if-two-integers-have-opposite-signs/#commentsFri, 25 Jul 2014 17:14:34 +0000adminhttp://www.beautifulwork.org/?p=15909
/* detect if two integers have opposite signs */
#include <stdio.h>
int x , y;
typedef int bool;
bool f;
int sdetect(x , y)
{
f = ((x ^ y) < 0);
if ( f == 1 ) {
printf("They have opposite signs\n");
}
else
{
printf("They have same signs\n");
}
}
]]>http://www.beautifulwork.org/2014/07/25/how-to-write-an-algorithm-to-detect-if-two-integers-have-opposite-signs/feed/0How to write a program to connect to a PostgreSQL server ? (program may not be perfect )
http://www.beautifulwork.org/2014/07/18/how-to-write-a-program-to-find-the-version-of-a-postgresql-server-program-may-not-be-perfect/?utm_source=rss&utm_medium=rss&utm_campaign=how-to-write-a-program-to-find-the-version-of-a-postgresql-server-program-may-not-be-perfect
http://www.beautifulwork.org/2014/07/18/how-to-write-a-program-to-find-the-version-of-a-postgresql-server-program-may-not-be-perfect/#commentsFri, 18 Jul 2014 19:43:42 +0000adminhttp://www.beautifulwork.org/?p=15904
#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 1;
}
else
{
printf("Connection established!\n");
serverversion = PQparameterStatus(conn,paramtext);
printf("Server Version: %s\n",serverversion);
}
PQfinish(conn);
return 0;
}
]]>http://www.beautifulwork.org/2014/07/18/how-to-write-a-program-to-find-the-version-of-a-postgresql-server-program-may-not-be-perfect/feed/0Tinkering with the fping command
http://www.beautifulwork.org/2014/07/16/tinkering-with-the-fping-command/?utm_source=rss&utm_medium=rss&utm_campaign=tinkering-with-the-fping-command
http://www.beautifulwork.org/2014/07/16/tinkering-with-the-fping-command/#commentsWed, 16 Jul 2014 15:03:14 +0000adminhttp://www.beautifulwork.org/?p=15902
$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 192.168.0.3
ICMP Host Unreachable from 192.168.0.103 for ICMP Echo sent to 192.168.0.3
ICMP Host Unreachable from 192.168.0.103 for ICMP Echo sent to 192.168.0.3
ICMP Host Unreachable from 192.168.0.103 for ICMP Echo sent to 192.168.0.3
ICMP Host Unreachable from 192.168.0.103 for ICMP Echo sent to 192.168.0.3
192.168.0.3 is unreachable
$fping -c1 192.168.0.1
192.168.0.1 : [0], 84 bytes, 0.29 ms (0.29 avg, 0% loss)
192.168.0.1 : xmt/rcv/%loss = 1/1/0%, min/avg/max = 0.29/0.29/0.29
$fping -c1 -s 192.168.0.1
192.168.0.1 : [0], 84 bytes, 0.27 ms (0.27 avg, 0% loss)
192.168.0.1 : xmt/rcv/%loss = 1/1/0%, min/avg/max = 0.27/0.27/0.27
1 targets
1 alive
0 unreachable
0 unknown addresses
0 timeouts (waiting for response)
1 ICMP Echos sent
1 ICMP Echo Replies received
0 other ICMP received
0.27 ms (min round trip time)
0.27 ms (avg round trip time)
0.27 ms (max round trip time)
0.000 sec (elapsed real time)
$
]]>http://www.beautifulwork.org/2014/07/16/tinkering-with-the-fping-command/feed/0