i have modified my code as little bit friends. Please have a look at it.
I will explain the flow of my code.
First for loop is to process numbers from 2 to 10. Then prints whatever the value is in i. lets say i=6
Inside this the second for loop is for this purpose. Iterate from 1 till the number before 6
Either (6%1) or (6/1) satisfies and sum<6 satisfies then
1.appending the factor (i.e 1) to the
string
2.appending the "+" symbol to the string
3.storing the factor in the sum so that when sum has reached 6 then it wont enter this if segment.
So as per my code first 1 enters and appended to string and added to sum then 2 and 3 also performs the same procedure and the sum value now is 6.
Therefore the next value of j is 4 and for this value if condition is dis satisfied now and moves to the else block.
here i am checking whether sum is 6 or not. Obviously our sum is 6 here so the status of the perfect number is set to true by default and it will not be modified by else block.
Then it encounters the labeled break statement stop and exits the for inner for loop. Since the status is true,it must print the factors that make 6 as a perfect number. I think my logic is correct.
But i get the following output now.
Perfect Number Perfect Makers
-------------- --------------
2 1+
3 Not a Perfect Number
4 Not a Perfect Number
5 Not a Perfect Number
6 Not a Perfect Number
7 Not a Perfect Number
8 Not a Perfect Number
9 Not a Perfect Number
10 Not a Perfect Number
I dont understand where i have went wrong
Please look at the code once and reply to this..