Hello again!<\/p>\n
For today’s quiz we had to write a code which could ask the user for undeterminated number of values and calculate the sum of the squares.<\/p>\n
For example:<\/p>\n
Let’s suppose that the user will introduce this values to the program:<\/p>\n
1, 2, 3, 4, 5.<\/strong><\/p>\n Now, what the program will do is the following:<\/p>\n 1^1+2^2+3^3+4^4+5^5<\/strong> and it will print 55<\/strong><\/p>\n When we want to stop giving values to our program it is indicated that the user must have to type 0.<\/strong><\/p>\n So, everything will look like this:<\/p>\n <\/p>\n And the execution of the program will look just like this:<\/p>\n <\/a><\/p>\n And, if you want to see my codes on GitHub, remember, just clic HERE.<\/a><\/p>\n Have an awesome week!<\/p>\n -The Admin<\/p>\n <\/a> <\/p>\n","protected":false},"excerpt":{"rendered":" Hello again! For today’s quiz we had to write a code which could ask the user for undeterminated number of values and calculate the sum of the squares. For example: Let’s suppose that the user will introduce this values to… Continue Reading →<\/a><\/p>\n","protected":false},"author":259,"featured_media":23413,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,3],"tags":[582,764,206,152,617,614,615,763],"_links":{"self":[{"href":"https:\/\/kenscourses.com\/tc101fall2015\/wp-json\/wp\/v2\/posts\/23415"}],"collection":[{"href":"https:\/\/kenscourses.com\/tc101fall2015\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kenscourses.com\/tc101fall2015\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kenscourses.com\/tc101fall2015\/wp-json\/wp\/v2\/users\/259"}],"replies":[{"embeddable":true,"href":"https:\/\/kenscourses.com\/tc101fall2015\/wp-json\/wp\/v2\/comments?post=23415"}],"version-history":[{"count":1,"href":"https:\/\/kenscourses.com\/tc101fall2015\/wp-json\/wp\/v2\/posts\/23415\/revisions"}],"predecessor-version":[{"id":23416,"href":"https:\/\/kenscourses.com\/tc101fall2015\/wp-json\/wp\/v2\/posts\/23415\/revisions\/23416"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/kenscourses.com\/tc101fall2015\/wp-json\/wp\/v2\/media\/23413"}],"wp:attachment":[{"href":"https:\/\/kenscourses.com\/tc101fall2015\/wp-json\/wp\/v2\/media?parent=23415"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kenscourses.com\/tc101fall2015\/wp-json\/wp\/v2\/categories?post=23415"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kenscourses.com\/tc101fall2015\/wp-json\/wp\/v2\/tags?post=23415"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}\/\/Sum the Squares of an undeterminated number of values<\/span>\n#include <iostream><\/span>\n#include <vector><\/span>\nusing<\/span> namespace<\/span> std;<\/span>\n\nint<\/span> sumsquares_list<\/span> (vector<<\/span>int<\/span>><\/span> v){<\/span>\nint<\/span> len<\/span> =<\/span> v.size();<\/span>\nint<\/span> sum<\/span> =<\/span> 0<\/span>;<\/span>\nfor<\/span>(<\/span>int<\/span> i<\/span> =<\/span> 0<\/span>;<\/span> i<\/span> <<\/span> len;<\/span> i++)<\/span> {<\/span>\nsum=<\/span> sum<\/span> +<\/span> (v[i]*v[i]);<\/span>\n}<\/span>\nreturn<\/span> sum;<\/span>\n}<\/span>\n\nint<\/span> main<\/span>()<\/span>\n{<\/span>\nint<\/span> c;<\/span>\nvector<<\/span>int<\/span>>v;<\/span>\ncout<<<\/span>\"Please introduce a serie of values and write 0 to finish.\"<\/span><<endl;<\/span>\/\/0 will be the signal to stop asking for values<\/span>\ncin<\/span> >><\/span> c;<\/span>\nwhile<\/span>(c<\/span> !=<\/span> 0<\/span>)<\/span> {<\/span>\nv.push_back(c);<\/span>\ncin<\/span> >><\/span> c;<\/span>\n}<\/span>\ncout<<<\/span>\"\"<\/span><<endl;<\/span>\ncout<<<\/span>\" The sum of the squares of the numbers that you typed in is: \"<\/span><<sumsquares_list(v)<<endl;<\/span>\nreturn<\/span> 0<\/span>;<\/span>\n}<\/span>\n<\/pre>\n<\/div>\n