Tuesday, 9 August 2016

Automorphic Numbers

Automorphic Numbers
In mathematics an automorphic number (sometimes referred to as a circular number) is a number whose square "ends" in the same digits as the number itself. For example, 52 = 25, 62 = 36, 762 = 5776, and 8906252 = 793212890625, so 5, 6, 76 and 890625 are all automorphic numbers. The only automorphic Kaprekar number is 1, because the square of a Kaprekar number cannot start with zero.
The sequence of automorphic numbers begins 1562576376625, 9376, ... (sequence A003226 in the OEIS).

Tuesday, 19 July 2016

For Versus While

Question: Is there any example for which the following two loops will not work same way?
/*Program 1 --> For loop*/
for (; ; )
{
   
}
 
/*Program 2 --> While loop*/
;
while ()
{
   
   
}
Solution:
If the body-statements contains continue, then the two programs will work in different ways
See the below examples: Program 1 will print “loop” 3 times but Program 2 will go in an infinite loop.
Example for program 1
int main()
{
  int i = 0;
  for(i = 0; i < 3; i++)
  {
    printf("loop ");
    continue;
  }
  getchar();
  return 0;
}
Example for program 2
int main()
{
  int i = 0;
  while(i < 3)
  {
    printf("loop"); /* printed infinite times */
    continue;
    i++; /*This statement is never executed*/
  }
  getchar();
  return 0;
}