Похожие чаты

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

38 просмотров

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

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

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

Господа, а что сейчас вообще с рынком труда на делфи происходит? Какова ситуация?
Мелодичный Сырник
29
А вообще, что может смущать в самой Julia - бы сказал, что нет единого стандартного подхода по многим моментам, поэтому многое выглядит как "хаки" и произвол. Короче говоря, с...
Фетровый Лингвист
2
@Benzenoid can you tell me the easiest, and safest way to bu.y HEX now?
Настойчивый Кварк
20
This is a question from my wife who make a fortune with memes 😂😂 About the Migration and Tokens: 1. How will the old tokens be migrated to the new $LGCYX network? What is th...
Льдистая Лужица
2
30500 за редактор? )
Замшевый Алхимик
47
а через ESC-код ?
Виноградная Притча
29
What is the Dex situation? Agora team started with the Pnetwork for their dex which helped them both with integration. It’s completed but as you can see from the Pnetwork ann...
Звенящий Циферблат
1
Гайс, вопрос для разносторонее развитых: читаю стрим с юарта, нада выделять с него фреймы с определенной структурой, если ли чо готовое, или долбаться с ринг буффером? нада у...
Туманный Ларец
9
Anyone knows where there are some instructions or discort about failed bridge transactions ?
Длинный Минерал
21
@lozuk how do I get my phex copies of my ehex from a atomic wallet, to move to my rabby?
Тягучая Ракушка
11
Карта сайта