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; }

7th Dec 2016, 3:35 PM
malik jutt
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.
7th Dec 2016, 4:24 PM
milk way
milk way - avatar
0
i also apply s=s/10
7th Dec 2016, 4:28 PM
malik jutt