2992 1234 0
2992 is a Sky Number. 1234 is not a Sky Number.#include<stdio.h> int main() { int n; int g,s,b,q,sk=0; int se[4],i,ak,m; int sl[4],j,bk,l; while(scanf(\"%d\",&n)!=EOF && n!=0) { /*************十进制**************/ q=n/1000; b=n%1000/100; s=n%1000%100/10; g=n%1000%100%10; sk=q+b+s+g; /************十二进制*************/ ak=0; m=n; for(i=0;m!=0;i++) { se[i]=m%12; m=m/12; } for(;i!=0;i--) ak+=se[i-1]; /************十六进制**************/ bk=0; l=n; for(j=0;l!=0;j++) { sl[j]=l%16; l=l/16; } for(;j!=0;j--) bk+=sl[j-1]; /************判断Sky***************/ if(bk==ak && ak==sk) printf(\"%d is a Sky Number.\\n\",n); else printf(\"%d is not a Sky Number.\\n\",n); } return 0; }
原文:http://blog.csdn.net/u013224148/article/details/43766869