Skip to content

Tag: for-loop

how to print a single output in for loop?

How can I print only one output in for loop? If the number is in array then it will print “Present” but if the number is not in the array it will print “Nope”. And I need to search the number the user inputed. Input: output: Expected Output: Present Answer You need to maintain a variab…

How to Flip the triangle?

How to flip this triangle? So i was making aritmethic sequance triangle. It was upside down. How do I turn it 180 degree? for example: 1=1 1+2=3 1+2+3=6 etc… my code: Answer You can do it for any n, by getting input from the user

Can we use semicolon independently at the beginning of a for-loop?

What is the meaning of this type of syntax in the for-loop? Answer A for statement is composed of 3 parts for(statement A; statement B; statement C): Statement A is the initializer statement. It is executed only one time. Usually, you create your variables you want to use in the for loop Statement B is the st…