0

Why time limit exceeds??

/*Wap to print sum and product of digits of integer */ #include <iostream> using namespace std; int main() { int n,sum=0,p=1; cout <<"Enter any integer \n"; cin>>n; for(int i=n;i!=0;i/10) { i=i%10; sum +=i; p*=i; } cout<<"Sum of digits :"<<sum<<"\n"<<"Product of digits : "<<p; return 0; }

3rd Aug 2019, 9:34 AM
Sahil Dahiya
Sahil Dahiya - avatar
1 Answer
+ 4
In the for loop, you should use i/=10 instead of i/10.
3rd Aug 2019, 9:37 AM
ä½ ēŸ„é“č¦å‰‡ļ¼Œęˆ‘也ę˜Æ
ä½ ēŸ„é“č¦å‰‡ļ¼Œęˆ‘也ę˜Æ - avatar