Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 17 Online
OpenStudy (anonymous):

How is the output to this code 17? sumDigits = 0 for c in str(1952): sumDigits += int(c) print sumDigits Any help would be truly appreciated.

OpenStudy (maitre_kaio):

I don't understand the question.

OpenStudy (anonymous):

Yeah, it is 17 in my Shell, you just have to run it. It sums up 1 + 9 + 5 + 2 and prints 17

OpenStudy (anonymous):

#include <stdio.h> #include <conio.h> void main() { int sumDigits = 0; int str[]={1,9,5,2}; for(i=0;i<4;i++) sumDigits += str(i); printf("The sum is %d",sumDigits); getch(); }

OpenStudy (maitre_kaio):

Your code sums the digits of the given string, here 1952. 1 + 9 + 5 + 2 = 17

OpenStudy (anonymous):

Thank you.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!