dev c++ - prime-armstrong number with C -
i newbie @ c language , working @ exercise: write c program print prime armstrong number b.
and code:
#include<stdio.h> #include<math.h> int p(int n){ int i; for(i=2;i<=n/2;i++){ if(n%i==0){ return 1; } } } int a(int n){ int i,a,b,c=0,e,p=0,j; a=n; while(n!=0){ n=n/10; c++; } e=a; while(a!=0){ j=a%10; p=p+pow(j,c); a=a/10; } if(e==p){ return 1; } } int main(){ int f1=1,f2=0,a,b,i; scanf("%d%d",&a,&b); for(i=a;i<=b;i++){ f1=p(i); f2=a(i); if(f1==0 && f2==1){ printf("%d prime armstrong number\n",i); }else{ printf("%d not prime armstrong number\n",i); } } return 0; } i searched on google prime armstrong numbers are: 28116440335967, 449177399146038697307, 35452590104031691935943,...
i want know, wrong code? or maybe result big , computer can not run program? used dev-c , computer-32bit. appreciate if can find answer.
Comments
Post a Comment