Write your question here.
1-Input: Take integer inputs from the user until she enters a negative number.
Output: The smallest of all the non-negative numbers entered by the user
2-Input: Take integer inputs from the user until she enters a negative number.
Output: The smallest and the 2nd smallest of all the non-negative numbers entered
3-Input: A non-negative integer n
Output: The T-number at index n, that is, Tn
plz give me code of these problems....i am beginner in programing....i felt difficulty in these problems....plz help out
Don't post homework questions
Those questions are for you to work out, so that you will learn from the experience. It is OK to ask for hints, but not for entire solutions.
The third task claims that the input is one integer, but the expected output comes from some indexed set. Where did that set came from?
Two major issues are immediate:
1) Your for loop will run forever for any positive n. Did you mean to decrement instead? you could do either for(int i(n); i > 0; --i) or for(int i(1); i < n+1; ++i).
2) Your if condition in the for loop is backwards. If n is smaller (not larger) than the current smallest number, then you assign n to smallest.
Edit:
But the whole code will eventually always say 1 is the answer (if n is any positive number).
I understand that you want it, but it is your responsibility to do your own homework. This would be cheating. We are not allowed to do your homework for you. But, if you have any questions about it, we can help you with that.