Похожие чаты

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 ответов

4 просмотра

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 (/* ... */) { /* ... */ } }

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

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

Is UniBright Freequity an active live product ? A friend here in Asia was discussing the Tokenisation of RWA’s in his case Real Estate as he’s a developer with numerous overs...
Digital Trust
4
коллеги, добрый вечер! А никто не знает как модальная форма может себя закрыть? Ну допустим модальная форма определила, что смысла ей работать нет и хочет вернуть modalResult...
Михаил
83
Привет, сталкивался кто с такой ситуацией? У меня есть модальное окно Bootstrap, в нем кнопка закрытия: <button type="button" class="btn-close" data-bs-dismiss="modal" aria-...
Виталий
3
Hi, is it fine to use git to backup my config? I did so many things that I don't want to miss if I switched to another OS, so how do you backup your home and configs? And shou...
Adnan Al_Beda
30
Hi Everyone! To all Are you Looking for Interview Support at the Lowest Price? Look no further! Then contact us We offer Interview Support for a low cost variety of technol...
Rambabu Nallamilli
3
How can I use this dvpn?
japolinux
11
верно что я могу удалить эти addq и subq т.к. со стеком никакого взаимодействия нет (исключая call)?
Michael
16
Добрый день задумываюсь о создание токена из за того что много свободного времени и вот я узнал что транзакции за перевод этого токена будут в waves и тут пришла идея при тран...
Артем
3
Добрый день Хочу начать обучение языку, не являюсь представителем it, буду благодарна за помощь, совсем пока не понимаю ничего) Подскажите, пожалуйста, где можно начать первы...
Sara Lala
28
А если изначально бот работал так : есть сайт онлайн школы. У каждого ученика свой кабинет. Где он авторизуется по своим данным. И уже в кабинете, на самом сайте делает оплату...
Денис 💡 Фрилансер
13
Карта сайта