TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Avuya Mxoli
NA
236
208.5k
The sum that is greater than the user input
Sep 2 2011 12:23 AM
Hello everyone, this is a class exercise that we were given to go think about and then we will share the answers in class...We are going to accept user input and then loop through adding to sum every time and checking if the value of sum is not bigger than the user input using pseudocode so here is my attempt and it is failing me(tested in c#):
accept input
i=1,sum = 0;
while sum<n
do
sum = 0;
FOR i =1 and i <= sum
sum = sum +i
i++
END FOR
display (sum)
I used 10 to test, the sum is supposed to stop at 15 because:1+2+3+4+5 = 15 but I got 17 I dont knw what im missing plz help
Thanks
Reply
Answers (
2
)
Random numbers
Why we say the time complexity of reading element in a Array is O(1)?