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; }
1 Resposta
+ 4
In the for loop, you should use i/=10 instead of i/10.