Write a function that computes the sum of the digits in an integer (integers with 3 digits only. Ex: 234, 345 etc)
Hint: Use the % operator to extract digits and the / operator to remove the extracted digit. For instance, to extract 4 from, use 234 % 10 (=4). To remove 4 from 234, use 234/10 (=23).
Here is a hard problem for C++ programmers.?
Feel kinda guilty doing homework questions so i figure i might as well spice it up by alternatively skipping the use of the modulous operator and giving you the pseudo code version of it (translate it to C++):
if (incInput / 100 %26lt;10 and %26gt;0) //Enforced rule check to make sure 3-digits only allowed
{
1stDigit = incInput /100;
incInput = incInput - 1stDigit*100;
2ndDigit = incInput /10;
incInput = incInput - 2ndDigit*10;
3rdDigit = incInput;
return (1stDigit + 2ndDigit + 3rdDigit);
}
Reply:is it a hard problem that needs ur hint
hahaha
Reply:You figured "I'll call it hard, so those stupid programmers will feel challenged"?
It's not hard, it's downright easy, but there were still some people who took the bait. Such a shame.
Do your own homework next time.
Reply:pseudo:
//x is a 3 digit number passed from main
int func(int x)
{ int a,b,c,d;
a= x%10
b=x/10
c = b%10
d = b/10
return (a+c+d)
}
You should double check, I just thought it was fun to try =)
Reply:man this is the place to ask question n not home work.
wedding florist
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment