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.

Saturday, 30 March 2013

PhD Admission Test Question Papers: PART - 3

  In this post I have given a few question papers and model papers of Admission Test conducted by Chennai Mathematical Institute for PhD in Computer Science and Engineering. I have also included question papers and model papers of Admission Test conducted by CMI for PhD in Mathematics, as this might also help the candidates in Computer Science.

Computer Science
Mathematics

Friday, 29 March 2013

C/C++ Puzzles: PART - 32

The sizeof character literal in C/C++

  Consider the C Program given below. 

#include<stdio.h>

int main()
{
    printf("\nSize of char is %d\n",sizeof(char));
    printf("\nSize of char 'a' is %d\n",sizeof('a'));
    return 0;
}


Figure Below Shows the Output

Now consider the case where the same code being executed as a C++ Program. The Program and Output is shown below.

include<stdio.h>

using namespace std;

int main()
{
  printf("\nSize of char is %d\n",sizeof(char));
  printf("\nSize of char 'a' is %d\n",sizeof('a'));
  return 0;
}


Figure Below Shows the Output

The same program gives different output when executed as C and C++ Programs. Why? This is because of a minor difference between C and C++. In C a character literal like 'a' is treated as an int, hence the size is 4 Byte. Whereas in C++ character literals are treated as characters and the size is just 1 Byte.