KodeKnight
  • Data Structures
    Array Stack Queue Linked List Tree Heap Graph Trie HashTable
  • Algorithms
    Recursion Divide And Conquer Greedy Dynamic Programming Backtracking Randomized Searching Sorting
  • About
    About Resume
  • Tags
  • Categories
  • Companies
  • Difficulty
  • Search
KodeKnight

Search KodeKnight

×
 
Custom Search
Sort by
Relevance
Date

cTricks


Give a fast way to multiply a number by 7

 Posted on January 3, 2010  (Last modified on August 7, 2020)  |  1 minutes  |  Kinshuk Chandra

Multiply by 8 (left shift by 3 bits) and then subtract the number.

(x << 3) - x
kodeknight  programming  c  cTricks  bits 

Given only putchar (no sprintf, itoa, etc.) write a routine putlong that prints out an unsigned long in decimal

 Posted on December 3, 2009  (Last modified on August 7, 2020)  |  1 minutes  |  Kinshuk Chandra

void putlong(unsigned long x)  
{  
// we know that 32 bits can have 10 digits. 2^32 = 4294967296  
for (unsigned long y = 1000000000; y > 0; y /= 10) {  
putchar( (x / y) + '0');  
x = x % y;  
}  
}  

kodeknight  programming  c  cTricks 

Kinshuk Chandra  • © 2020  •  KodeKnight

Hugo v0.74.3 powered  •  Theme Beautiful Hugo adapted from Beautiful Jekyll