All language subtitles for 18. Sum of Odd Numbers Sequence - Solution

af Afrikaans
ak Akan
sq Albanian
am Amharic
ar Arabic
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bem Bemba
bn Bengali
bh Bihari
bs Bosnian
br Breton
bg Bulgarian
km Cambodian
ca Catalan
chr Cherokee
ny Chichewa
zh-CN Chinese (Simplified)
zh-TW Chinese (Traditional)
co Corsican
hr Croatian
cs Czech
da Danish
nl Dutch
en English
eo Esperanto
et Estonian
ee Ewe
fo Faroese
tl Filipino
fi Finnish
fr French
fy Frisian
gaa Ga
gl Galician
ka Georgian
de German
el Greek
gn Guarani
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hu Hungarian Download
is Icelandic
ig Igbo
id Indonesian
ia Interlingua
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
rw Kinyarwanda
rn Kirundi
kg Kongo
ko Korean
kri Krio (Sierra Leone)
ku Kurdish
ckb Kurdish (Soranî)
ky Kyrgyz
lo Laothian
la Latin
lv Latvian
ln Lingala
lt Lithuanian
loz Lozi
lg Luganda
ach Luo
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mfe Mauritian Creole
mo Moldavian
mn Mongolian
sr-ME Montenegrin
ne Nepali
pcm Nigerian Pidgin
nso Northern Sotho
no Norwegian
nn Norwegian (Nynorsk)
oc Occitan
or Oriya
om Oromo
ps Pashto
fa Persian
pl Polish
pt-BR Portuguese (Brazil)
pt-PT Portuguese (Portugal)
pa Punjabi
qu Quechua
ro Romanian
rm Romansh
nyn Runyakitara
ru Russian
gd Scots Gaelic
sr Serbian
sh Serbo-Croatian
st Sesotho
tn Setswana
crs Seychellois Creole
sn Shona
sd Sindhi
si Sinhalese
sk Slovak
sl Slovenian
so Somali
es Spanish
es-419 Spanish (Latin American)
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
tt Tatar
te Telugu
th Thai
ti Tigrinya
to Tonga
lua Tshiluba
tum Tumbuka
tr Turkish
tk Turkmen
tw Twi
ug Uighur
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
wo Wolof
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu
Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated: 1 00:00:00,300 --> 00:00:08,070 All right, so what we have to do in this exercise is simply to write a program that receives some and 2 00:00:08,250 --> 00:00:18,030 some value and from the user so receives and from the user and based on these and we are going to receive 3 00:00:18,240 --> 00:00:27,270 OK to receive or receive or read and values or better say, integers. 4 00:00:28,080 --> 00:00:38,670 And we are going to sum all the odd numbers and to return and to basically print these some sum, all 5 00:00:38,670 --> 00:00:40,650 the old numbers. 6 00:00:40,950 --> 00:00:49,770 OK, so how we are going to do that, let's start with just creating the variable and reading this value 7 00:00:49,770 --> 00:00:54,410 once again from the user and storing it inside of an variable. 8 00:00:54,420 --> 00:01:06,900 So an answer and which is also the number of values, a number of values in a sequence of numbers that 9 00:01:06,900 --> 00:01:08,480 we are going to insert. 10 00:01:08,490 --> 00:01:08,810 Right. 11 00:01:08,820 --> 00:01:12,150 So enter and some. 12 00:01:12,490 --> 00:01:20,960 And now let's read this value from the user and story inside the variable and so storing inside variable 13 00:01:20,970 --> 00:01:21,200 in. 14 00:01:21,770 --> 00:01:26,670 And now what we are going to do is just to use some loop. 15 00:01:27,090 --> 00:01:27,510 Right. 16 00:01:28,170 --> 00:01:31,170 And this is going to be very, very simple. 17 00:01:31,500 --> 00:01:37,380 Let's say we have here I sell for I equals to you. 18 00:01:37,380 --> 00:01:38,190 To what? 19 00:01:38,190 --> 00:01:46,070 To what should be I equal to R equals, let's say to one, as long as I use less than or equal to N. 20 00:01:47,220 --> 00:01:48,810 Okay I plus plus. 21 00:01:49,200 --> 00:01:52,060 So one way to do that is to use the for loop. 22 00:01:52,100 --> 00:01:59,070 Another way to do that is to use the wire loop as long as it is greater than one or zero, whatever 23 00:01:59,070 --> 00:02:01,860 you choose using the greater than or equal. 24 00:02:02,430 --> 00:02:04,080 OK, so let's go with the four. 25 00:02:04,230 --> 00:02:12,330 No problems with four equals to one as long as I is less than or equal to and basically are making the 26 00:02:12,330 --> 00:02:15,570 easy duration in times. 27 00:02:16,440 --> 00:02:20,910 OK, so now let's just read the value from the user. 28 00:02:21,360 --> 00:02:29,550 Let's say we will have also additional variable called current value and we will simply read the value 29 00:02:29,550 --> 00:02:33,870 from the users or print f cancer of value and zero value. 30 00:02:36,270 --> 00:02:41,240 Now read this value from the user so it inside current value. 31 00:02:42,150 --> 00:02:44,580 And now we have to ask a simple question. 32 00:02:44,970 --> 00:02:56,910 If current value divided by two modulo two equals to one, which means it's it's an odd number, then 33 00:02:56,910 --> 00:03:02,150 in this case we should basically some this solution, these value. 34 00:03:02,580 --> 00:03:07,140 So let's say also all the sum will be equal to zero. 35 00:03:07,150 --> 00:03:08,940 So on some will be equal to zero. 36 00:03:09,780 --> 00:03:14,820 There you go on some loss equals two to watch to the current value. 37 00:03:15,360 --> 00:03:20,530 OK, so that's how you sum up all the old values in this sequence. 38 00:03:20,820 --> 00:03:23,100 And finally, you're going to print. 39 00:03:23,190 --> 00:03:27,680 OK, so all that sum equals to percentage. 40 00:03:29,190 --> 00:03:30,510 And there you go. 41 00:03:32,680 --> 00:03:39,040 And yeah, I think that we covered up everything as we should, so let's build and run it to see that 42 00:03:39,040 --> 00:03:44,350 everything works correctly so and will represent the size of the sequence. 43 00:03:44,380 --> 00:03:48,540 So, for example, five, let's go like one, two, three, four and five. 44 00:03:49,000 --> 00:03:51,280 So we have some problem. 45 00:03:51,320 --> 00:03:52,300 So what's the problem? 46 00:03:52,300 --> 00:03:55,270 Osam equals to some odd, very odd number. 47 00:03:55,280 --> 00:03:56,080 Very strange. 48 00:03:56,680 --> 00:04:02,410 So we can see here that we didn't specify is instead of the placeholder here instead of the percentage, 49 00:04:03,040 --> 00:04:06,770 what will be the values of the value should be or something. 50 00:04:07,420 --> 00:04:12,870 So let's hopefully build and run it once again and see that everything works correctly. 51 00:04:12,880 --> 00:04:15,180 So one, two, three, four and five. 52 00:04:15,520 --> 00:04:17,650 So all some equals to nine. 53 00:04:17,650 --> 00:04:23,500 And let's make sure that five plus three, which is eight plus one, which is nine awesome. 54 00:04:24,280 --> 00:04:34,120 And similar approach can also be done for finding also the even values and also finding the the odd 55 00:04:34,120 --> 00:04:39,790 sum and the even some basically we can also find both of them in a sequence. 56 00:04:40,060 --> 00:04:45,580 So these are kind of questions that a lot of teachers like to ask students. 57 00:04:46,330 --> 00:04:53,200 But now you know how you can tackle this problem even without using arrays, which we haven't covered 58 00:04:53,200 --> 00:04:55,470 up yet, but we will talk about them. 59 00:04:55,840 --> 00:05:05,770 So you simply get some value from the user and they and specify the size of the sequence that you are 60 00:05:05,770 --> 00:05:06,670 going to use. 61 00:05:06,940 --> 00:05:11,020 Then you readjust these values one by one, asking some conditions. 62 00:05:11,230 --> 00:05:17,160 And since you don't care to store these values for later, use it. 63 00:05:17,560 --> 00:05:22,640 That's why probably this approach is one of the best. 64 00:05:23,200 --> 00:05:24,780 So thank you guys for watching. 65 00:05:25,060 --> 00:05:27,370 I'll see you in the next video. 6225

Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.