Wednesday, 17 April 2013

C/C++ Program to Print Large Fibonacci Numbers

   The Fibonacci Series is  0, 1, 1, 2, 3, 5, 8, 13, 21, ... Printing the Fibonacci Numbers is a very trivial task for any person familiar with the basics of programming. But what happens when you have to print very large Fibonacci numbers? Then C/C++ or even languages like MATLAB or Mathematica may not have sufficiently large data types to store the results. In this C/C++ Program I have used an array to store Fibonacci Numbers. The C Program also  stores the results into a text file called fib.txt.

Figure Below Shows a Sample Output



Sunday, 14 April 2013

C/C++ Program to Print Number Spiral Matrix

Consider the following 5 X 5 Matrix. The numbers are printed as a spiral in the matrix starting with 1.

21 22 23 24 25
20  7  8  9 10
19  6  1  2 11
18  5  4  3 12
17 16 15 14 13

The C/C++ Program provided in this Post prints Number Spirals of arbitrary size.

Figure Below Shows Sample Output for a 9 X 9 Matrix

Friday, 12 April 2013

C/C++ Program to Truncate Integers

Consider the Integer 12345. The Number can be truncated from both the left side and the right side to get the output shown in the figure. The C/C++ Program given in this post truncates Integers and prints them.

Figure Below Shows a Sample Output


Click here to download the C++ Program.

C/C++ Program to Print Truncatable Primes

  The number 3797 has an interesting property. Being prime itself, it is possible to continuously remove digits from left to right, and remain prime at each stage: 3797, 797, 97, and 7. Similarly we can work from right to left: 3797, 379, 37, and 3. Remember 2, 3, 5, and 7 are not considered to be Truncatable Primes. The C/C++ Program in this post prints Truncatable Primes truncatable from both left and right. 

Figure Below Shows a Sample Output

C/C++ Program to Print Double-Based Palindromes

  A number is called a Double-based palindrome, if it is palindromic for two different bases. For example consider the decimal number 585. 58510 = 10010010012 (Binary), is palindromic in both bases.Thus 585 is a Double-based palindrome. The C/C++ Program discussed in this post prints Double-based palindromes less than a given limit.

Figure Below Shows a Sample Output

Sunday, 7 April 2013

C/C++ Program to Print Circular Prime Numbers

   A circular prime is a prime number with the property that the number generated at each intermediate step when cyclically permuting its (base 10) digits will be prime.The number, 379, is a circular prime because all rotations of the digits: 793, 937, and 379, are themselves prime numbers. The C/C++ Program provided in this Post prints all the Circular Prime numbers less than the given limit.

Figure Below Shows a Sample Output



Click here to download the C++ Program.

C/C++ Program to Print the Cyclic Permutations of a Number

  Consider the number 1234. The number can be cyclically rotated to obtain the following numbers 4123, 3412, 2341, and 1234. The C/C++ Program in this Post prints the Cyclically Shifted numbers obtained from a given number.

Figure Below Shows a Sample Output


Click here to download the C++ Program.