#include
using namespace std;
int main()
{
int N,num,rem,sum=0,temp;
cin>>N;
for(int i=0;i<N;i++)
{
cin>>num;
temp=num;
while(temp!=0)
{
rem=temp%10;
sum=sum+rem;
temp=temp/10;
}
cout<<sum<<endl;
}
}
my code is printing the sum of the first input and then adding this value to the sum of tbe next input.I was trying this so as to know the sum.The code cannot be written by me further because I am facing problem in the initial steps itself.Please help.
Delhi's odd even
In this question you have to take the sum of even digits and odd digits separately. Then you have to check whether the sum of even digits is divisible by 4 or sum of odd digits is divisible by 3. If one of the conditions comes out to be true, then you have to print “Yes”, else print “No”.
For eg : the number of car is 45123, sum of odd digits is 5+1+3 = 9 and sum of even digits is 2+4 = 6.
Sum of odd digits is divisible by 3, so you have to print “Yes”.
And regarding the sum, you have to initialize to 0 in the beginning of every iteration of the loop, so that it does not carry the value from the previous iteration.
thanks a lot for your help.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.