Monday, 3 July 2017

MAGIC SQUARE PUZZLE


/*
 * C Program to Solve the Magic Squares Puzzle without using 
 * Recursion
 */
#include

void magicsq(int, int [][10]);

int main( )
{
    int size;
    int a[10][10];

    printf("Enter the size: ");
    scanf("%d", &size);
    if (size % 2 == 0)
    {
        printf("Magic square works for an odd numbered size\n");
 A   }
    else
    {
        magicsq(size, a);
    }
    return 0;
}

void magicsq(int size, int a[][10])
{
    int sqr = size * size;
    int i = 0, j = size / 2, k;

    for (k = 1; k <= sqr; ++k) 
    {
        a[i][j] = k;
        i--;
        j++;

        if (k % size == 0) 
        { 
            i += 2; 
            --j; 
        }
        else 
        {
            if (j == size) 
            {
                j -= size;
            }
            else if (i < 0)
            {
                i += size;
            }
        }
    }
    for (i = 0; i < size; i++)
    {
        for (j = 0; j < size; j++)
        {
            printf("%d  ", a[i][j]);
        }
        printf("\n");
    }
}
RUN IT..............

Thursday, 29 June 2017

ALGEBRA MAGIC

#include
#include

int main()
{ 
 int x,y;
 printf("Think of a munber Between 60 and 100 .\nProvided The number should not consist of the values 0&1.\nPress Enter Key When Ready");
 getch();
 printf("\nNow add the number with its reverse.\neg.62+26\nif the number you thought was 62.\npress Enter when ready.");
 getch();
 printf("\nEnter the Middle value of your answer = ");
 scanf("%d",&x);
 y=100+(x*10)+(x-1);
 printf("The value you got is = %d",y);
 getch();
}

Run this and see the magic !!!!!!!

Tuesday, 27 June 2017

More on printf

What will be the output of following code 

#include

int main()
{

         printf("%d",printf("computer"));

         return (0);

}

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 1, 5, 6, 25, 76, 376, 625, 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;
}