Похожие чаты

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

8 просмотров

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

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

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

Всем привет, написал код ниже, но он выдает сегфолт, в чем причина? #include <stdio.h> #include <stdlib.h> #include <string.h> struct product { char *name; float price; };...
buzz базз
32
Хотел бы спросить у знающих, правильную ли я выбрал книгу для начала изучения ассемблера Юрова В.И ? Или есть более лучшие книги для начала обучения?
Botsman
25
Добрый день, не подскажите, если в OC-V3 поменять страндартную директорию /storage/ на /storage2/ - не будет сильно много проблем ?
Max Dubovsky
32
Conversation at a festival with a non-crpto person (not a normie by any stretch, though): * person: tell me about crypto, me: ok, the original idea is p2p sound money for the...
molecular#123 🐓
25
Книга Юрова В.И пойдёт для обучения?
Botsman
24
$params = [ 'formid' => 'feedbackForm', 'formTpl' => '@CODE: <form class="form-validate" data-id="ajax_form"> <fieldset class="margin-bottom-md"> ...
Pathologic
1
> Примечательно, что новый владелец удаляет из GitHub любые жалобы, указывающие на подозрительную активность или смену владельца, и, видимо, рассчитывает на то, что пользовате...
Alex Sherbakov
1
I bought some PHA tokens on Kucoin, which is the best wallet to store and easy to use?
AMR
19
'frakturBold' => ['𝖆', '𝖇', '𝖈', '𝖉', '𝖊', '𝖋', '𝖌', '𝖍', '𝖎', '𝖏', '𝖐', '𝖑', '𝖒', '𝖓', '𝖔', '𝖕', '𝖖', '𝖗', '𝖘', '𝖙', '𝖚', '𝖛', '𝖜', '𝖝', '𝖞', '𝖟', '𝕬', '𝕭', '𝕮', '𝕯'...
Roma
4
Подскажите пожалуйста, а я могу вот такую штуку использовать? rpc, только реализованное в реббите https://www.rabbitmq.com/tutorials/tutorial-six-php ( или https://habr.com/ru...
Artyom
11
Карта сайта