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");
}

No comments:

Post a Comment