How to display in a block diagram a code fragment if (d<1 || d>amountofdays(m)) written in C?
- 2But how do the flowcharts look like in C? - Grundy
- @Grundy It is meant here that a part of the C code is translated into a block scheme. - Jenssen
2 answers
Depends on the required level of detail of the algorithm.
If the amountofdays function amountofdays considered elementary, then it will be a single “Decision” block (diamond), where you should write: d<1 || d>amountofdays(m) d<1 || d>amountofdays(m) .
If you need to emphasize the call amountofdays as a subroutine, you will have to disclose all language constructs. First there will be a “Decision” block for condition d<1 , then a “Predefined process” block for calling d0 := amountofdays(m) and finally one more “Decision” block with checking d>d0 .
PS but, generally speaking, the flowchart at the moment is the stupidest of the code documentation options. Because of the same level of detail, which is consistently lower than that of the code itself. If this is not an educational task, then it is better to look for other ways of visualization (for example, UML or some IDEF).
- Thank you very much for such a meaningful answer. The task is educational. I can clarify, i.e. you just need to make two of one condition and insert a call block between them (pre-process)? Exactly the order of actions, which the program carries out as a result, interests. - Difmus
- @Difmus is the problem of all educational tasks - the answer to them depends heavily on the teacher, and this is no exception. - Pavel Mayorov
- @Difmus and on the order of execution - google short circuit logic operators - Pavel Mayorov
Yes, as in any other language.
Rhombus, inside it you write the condition d <1 || d> amountofdays (m). From the diamond goes 2 lines from two sides. Over the first line you write true, over the second false. Well, depending on which answer returns, it goes on already or a rhombus - if the condition goes further, or a square - if any commands are executed.
- Only the if condition in the flowchart looks like a diamond, so in practice we designated it in school. Or has something changed already? - Jenssen
- so this one "square" should be - Grundy
- @Jenssen, yes, it was a long time ago, I forgot. I’ll fix it :) - EVG
- I need to separately mark the actions of the function as subroutines. After all, I suppose, in the flowchart, a “predefined processor” block is needed with a function call in any case, if it is present? But the call is enclosed in a block with a condition, so I don’t know how to designate it, and in what order the condition will be executed when the program calls the function at all. I hope, understand what I'm talking about) - Difmus