What is the output of the following flowchart if n= 10? Explain with reason
All Answers
total answers (1)
Severity: 8192
Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated
Filename: libraries/Filtered_db.php
Line Number: 23
total answers (1)
Output:
55
Explanation:
First when the program starts it askes to enter a number, in this case the entered number n is 10, then initializing variable sum =0 and uses variable i as counter from 1 to n.
Then the program will check if i <=n when it yes it will add i value to the sum and when it is no it will display the sum of numbers from 1 to 10.
So at first for i=1 it will check is 1 <= 10 ? it is yes, so 1 will be added to sum which was zero so the new sum= 1+0 =1 ,then i will be incremented by 1 so new become i =2.
Then again check is 2 <=10 ? it is yes, so 2 will be added to sum which was equal to 1 so the new sum= 1+2 =3, then i will be incremented by 1 so new become i =3.
Then again check is 3 <=10 ? it is yes, so 3 will be added to sum which was equal to 3 so the new sum= 3+3 =6 And so on till i=11 then check is 11 <=10? it is no, then the program will display the sum (1+2+3+4+5+6+7+8+9+10=55)and stops.