The problem asks to print all number that are equal to their digits ^n
e.g 1634=1^4+6^4+3^4+4^4...So it should show all numbers from 1000 to 9999...
I did this and the programm stops working :
Code:
#include <stdio.h>
#include <cstdlib>
// k =psifia n=dunami
main()
{
int i,j,ar1,ar2,ar3,ar4,Din1,Din2,Din3,Din4,x,k,n,l,p_orio,d_orio,p,dig[16],Din[16],sum,id=0;
printf("Dwse to k kai to n\n");
scanf("%d %d",&k,&n);
p_orio=1;
d_orio=1;
for (l=1; l<k; l++){
p_orio=10*p_orio;
}
for(p=1; p<=k; p++){
d_orio=10*p_orio-1;
}
printf("emfanise %d %d\n",p_orio,d_orio);
for(i=p_orio; i<=d_orio; i++){ //in case i add k=4,n=4 p_orio=1000 d_orio=9999
while (i>0){
dig[id]=i%10;
i/=10;
id++;
}
for (j=1; j<=n; j++){
Din[j]=1;
}
for (j=1; j<=n; j++){
Din[j]=Din[j]*dig[id];
sum=sum+Din[j];
}
if (i==sum){
printf("oi arithmoi einai pou einai upswmenoi stin %di dynami einai oi: %d\n",n,i);
}
}
system("pause");
}