Vampire
Number :
A
vampire number a composite natural number must consists even digit of numbers
that can be divided ito two equal parts as x and y. Both parts are know as
fangs and both cannot ends with trailing zeroes. A number can be considered a
Vampire number when product of the fang produce the same number and it can be
in any order.
Example:
1260 is a vampire number, with 21 and 60 as fangs, since 21 × 60 = 1260.
126000
= 210 × 600 is not, as both 210 and 600 have trailing zeroes.
Some
other Vampire Numbers are : 1395, 1435, 1530, 1827, 2187, 6880, 102510.
//Checking if a
given number is a Vampire Number or not
#include <stdio.h>
#include <conio.h>
#include <math.h>
#include <string.h>
int Digit(int n)
{
int
c=0;
while(n>0)
{
c++;
n/=10;
}
return
c;
}
void
sort(char Kc[])
{
int i,j;
char ch;
for(i=0;i
{
for(j=0;j
{
if(Kc[j]>Kc[j+1])
{
ch=Kc[j];
Kc[j]=Kc[j+1];
Kc[j+1]=ch;
}
}
}
//A series of Vampire Numbers
#include <stdio.h>
#include <conio.h>
#include <math.h>
#include <string.h>
int Digit(int n)
{
int
c=0;
while(n>0)
{
c++;
n/=10;
}
return
c;
}
void
sort(char Kc[])
{
int i,j;
char ch;
for(i=0;i
{
for(j=0;j
{
if(Kc[j]>Kc[j+1])
{
ch=Kc[j];
Kc[j]=Kc[j+1];
Kc[j+1]=ch;
}
}
}
}
void
print(int a[],int i)
{
int j;
print("\n\tVampire Numbers : \n"”);
for(j=0;j
{
printf("\n\t%d
",a[j]);
}
}
void main()
{
int i,j,k,c,a[100],t=0,flag;
char *kStr,*catStr,*tmp;
clrscr();
for(i=11; i<=100; i++)
{
for(j=11; j<=100; j++)
{
flag=0;
c=Digit(i*j);
if(c%2!=0)
{
continue;
}
if(i%10==0
&& j%10==0)
{
continue; //both fangs cannot have trailing '0'
}
k = i * j;
catStr[0]='\0';
tmp[0]='\0';
kStr[0]='\0';
itoa(k,kStr,10);
itoa(i,catStr,10);
itoa(j,tmp,10);
strcat(catStr,tmp);
sort(kStr);
sort(catStr);
if(strcmpi(kStr,catStr)==0)
{
for(k=0;k
{
if(a[k]==i*j)
{
flag=1;
break;
}
}
if(flag==0)
{
a[t++]=i*j;
}
}
}
}
print(a,t);
getch();
}
No comments:
Post a Comment