0
Find error
#include<iostream> using namespace std; int main(){ int r; long sum=0,num,c,s; cout<<"enter number "; cin>>num; for(c=1;c<=num;c++) { s=c; while(s!=0) { r=s%10; sum=sum+(r*r*r); s=s/10; } if(c==num){ cout<<c<<endl;} } sum=0; return 0; }
2 Answers
0
The problem which I think in this program is that the variable s will never be 0 because you started c as 1 and assigned it to s. this leads to infinite loop.
0
i also apply s=s/10