Похожие чаты

Hi, anyone could answer me this? I've searched but still

don't get it. I have a main with just some code to tell me hoy many numbers are multiple of 3 or 5. So, here's the code to see: https://paste.ofcode.org/77fqtRzi6DkPJqDHY6HWNr
What I don't get is how does it work with those scanf(): one outside of the while loop saves me from having to initalize the variable num to 0 so it doesn't break the while. And the scanf() inside of the while loop checks all the numbers from my input to see if there's a 0 to end the while. If I delete one of those scanf(), it doesn't work. How's that?

3 ответов

12 просмотров

If you delete the inner scanf, there is no terminating condition for your loop. Also, that inner scanf is the only thing that stops your loop. If you remove that one, then suppose you enter 15 in the outer scanf, then the program will enter an infinite loop. Each time checking if 15 is a multiple of 3 and 5, then incrementing cont and doing the same thing again and never stopping.

Use “long long int” instead of “int”; and you know what to change from %d.. to..

you can simplify this as int num; int cont = 0; while (scanf("%d", &num) == 1 && num > 0) { if (/* ... */) { /* ... */ } }

Похожие вопросы

Обсуждают сегодня

Всем привет! Имеется функция: function IsValidChar(ch: UTF8Char): Boolean; var i: Integer; ValidChars: AnsiString; begin ValidChars := 'abcdefghijklmnopqrstuvwxyzABCDE...
Евгений
44
For all those that keep asking why no pump? why this ? and why that...? Please close ur ewt chart and open 2 others - TOTAL (total mc) and BTC.D (btc dominance). Maybe BTC a...
Inn3r_G
19
"Since pnut can flip FTM easily, I'm swapping my FTM to pnut and hoping for a easy x5-x10" Perfect recipe for disaster. NFA but chances are, you'll end up as exit liquidity ...
C. A.
7
AMD status update? No longer in the plan but something might be around the corner later on Chinese partner? No longer in the plan. This market does not seem to be the top ...
Ben
6
I get confused when people talk about the ‘bull market’ and the ‘next bull market’ as if anyone really has a clue what’s really going on in the world. First of all - there i...
Shah
1
Добрый день, подскажите, пожалуйста, по проблеме. Сегодня на работе утром обнаружилось что по рдп подключиться не получается к серверу 2022. В серверную зашел - на системно...
srv
19
Ready for some fun AND a chance to win TKO Tokens? Join us for exciting minigames in our Telegram group! 🕒 Don’t miss out—games start on today 25 October 2024, at 8 PM! Ge...
Milkyway | Tokocrypto
255
лучше скажите, причём тут паскаль?
Alexey Kulakov
36
Чтобы перехватить все нажимания буков на форме, надо хук ставить? Пробовал на форме ОнКейДаун, оно ловит клаву если фокус не на компоненте с вводом текста
Serjone
15
Народ! Впервые клиенту пришло письмо от РКН, у вас, дескать, есть яндекс метрика, а нигде не написано, что вы ее юзаете. Никто не сталкивался?
Sasha Beep
14
Карта сайта