Search This Blog

Program to check whether a given number is a pythons number

A number is said to be pythons number if  digits in the number are powers of the first digit,
for example, a number 24816 is a pythons number because
4=2^2
8=2^3
16=2^4
Other examples are 392781,41664,etc
//source code:

 #‎inc‬ lude. <stdio.h>  
 ‪#‎in‬ clude<math.h>  
 void main(){  
 int c1=0, c2=0, c3=0,p=2;  
 int z,d,x,y,f;  
 unsigned long int n,temp,q;  
 printf("\n Enter a number:");  
 scanf("%d",&n);  
 temp=n;  
 while ( temp ){  
 c1++;  
 temp = temp / 10;  
 }  
 c2 = c1 - 1;  
 x =n / pow(10,c2);  
 y = pow(10,c2);  
 q = n%y;  
 while (q)  
 {  
 c3 = 0;  
 z = pow(x,p);  
 p++;  
 f=z;  
 while (f)   
 {  
 c3++;  
 f = f / 10;  
 }  
 c2 = c2 - c3;  
 if(c2<0)  
 break;  
 d=q/pow(10,c2);  
 y = pow(10,c2);  
 q = q%y;  
 if (d!=z) {  
 c2=1;  
 break;}  
 }  
 if (c2==0)  
 printf("Given number is a pythons number");  
 else   
 printf("Given number is not a pythons number");  
 } 
OUTPUT:

No comments:

Post a Comment

leave a comment here