[youtube https://www.youtube.com/watch?v=AfQxyVuLeCs?rel=0&w=480&h=360]
Author Archives: jeffrin
How to write an algorithm to do a binary to decimal conversion ?
/* part of work copied from http://www.sanfoundry.com/c-program-binary-number-into-decimal/ */ #include <stdio.h> btd() { int num, binary_val, decimal_val = 0, base = 1, rem; printf(“Enter a binary number : “); scanf(“%d”,&num); binary_val = num; while ( num > 0 ) { rem = num % 10; decimal_val = decimal_val + rem * base; num = num / …
Continue reading “How to write an algorithm to do a binary to decimal conversion ?”
How to write an algorithm to swap values ?
/* part of work copied from http://www.sanfoundry.com/c-program-swap-values/ */ #include <stdio.h> swap_values() { int temp; int *ptr1, *ptr2; int a, b; printf(“Enter integer values to be swapped: “); scanf(“%d %d”,&a,&b); ptr1 = &a; ptr2 = &b; temp = *ptr1; *ptr1 = *ptr2; *ptr2 = temp; printf(“Swapped values are: %d %d \n”,a,b); } /* http://www.programmingsimplified.com/c-program-swap-two-numbers */ /* …
Continue reading “How to write an algorithm to swap values ?”
Hacking with integer divisibility
/* work copied from http://www.sanfoundry.com/c-program-number-divisible-by-5/ */ #include <stdio.h> numberdivi() { int i, num1, num2, count = 0, sum = 0; printf(“Enter the value of num1 and num2 : “); scanf(“%d %d”,&num1,&num2); for (i = num1; i < num2 ; i++) { if ((i % 5) == 0) { printf(“%3d,”,i); count++; sum = sum + i; …
Hacking with a binary using file and strip commands
$file simple | awk ‘{ print $(NF-1) $(NF-0) }’ notstripped $du -h simple 8.0K simple $./simple Hello World $strip ./simple $du -h simple 8.0K simple $./simple Hello World $file simple | awk ‘{ print $(NF-1) $(NF-0) }’ BuildID[sha1]=6cf0bed752a904372cd42a85bc560c266a7c91b3,stripped $
Hacking with debian netselect-apt command
$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 …
Continue reading “Hacking with debian netselect-apt command”
How to write an algorithm to find factorial of a given number ?
#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); }
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 …
Continue reading “Hacking with an algorithm to find prime factor of a number”
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 …
Continue reading “How to write an algorithm to find if a number is palindrome or not”
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 …
Continue reading “Tinkering with an Armstrong number finding program function”