Auto AdSense

Monday, 27 April 2015

C Program to find Lucky Number

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
long int sumf(long int x)
{
    long int s;
    for(s=0;x>0;s+=x%10,x/=10);
    return s;
}
void main()
{
    long int sum=0;
    int a[26],i,k;
    char s[99];
    l1:
    printf("\n Enter your name without spaces:");
gets(s);
for(i=0;i<strlen(s);i++)
{
if(s[i]>=65&&s[i]<=90)
a[i]=s[i]+32;
else
a[i]=s[i];
}
  for(i=0;i<strlen(s);i++)
  {
  if(a[i]<97||a[i]>122)
  {
  printf("\n Invalid Character Please Try again");
  goto l1;
}
}
    for(i=0;s[i]!='\0';i++)
        sum=sum+a[i];
    while(sum>=10)
        sum=sumf(sum);
    k=sum;
    printf("\n\n\n\t Your lucky number\n\t according to the name is : %ld ",sum);
    printf("\n\n Enter your date of birth : ");
    scanf("%ld",&sum);
    while(sum>=10)
        sum=sumf(sum);
    printf("\n\n\t Your lucky number\n\t according to the date of birth is : %ld ",sum);
    if(k==sum)
        printf("\n\n\t You are the Luckiest Person");
}

Saturday, 4 April 2015

Tower of Hanoi Solutions upto 10 disks

        The Tower of Hanoi (also called the Tower of Brahma or Lucas' Tower, and sometimes pluralized) is a mathematical game or puzzle. It consists of three rods, and a number of disks of different sizes which can slide onto any rod. The puzzle starts with the disks in a neat stack in ascending order of size on one rod, the smallest at the top, thus making a conical shape.



The objective of the puzzle is to move the entire stack to another rod, obeying the following simple rules:
  • Only one disk can be moved at a time.
  • Each move consists of taking the upper disk from one of the stacks and placing it on top of another stack i.e. a disk can only be moved if it is the uppermost disk on a stack.
  • No disk may be placed on top of a smaller disk.

With three disks, the puzzle can be solved in seven moves. The minimum number of moves required to solve a Tower of Hanoi puzzle is 2n - 1, where n is the number of disks.