help required

Pages: 12
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
Forum sticky wrote:
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?
Last edited on
plz tell me how i can write the condition of smallest number in while loop
plz plz plz tell the solution of 3rd programm.........only one program plx plx plz....i have already waste the 3 hours at this problem
Post your "3 wasted hours" code ;)
#include <iostream>

using namespace std;

int main ()
{
int n=1,smallest=0;

while ( n>0 )
{
cout<<"Enter a number"<<endl;
cin>> n;
}

smallest=n;

for (int i = n; i > 0 ; i++)
{
if(n>smallest)
smallest=n;
}

cout<< "smallest non-negative number is :" << smallest << endl;

return 0;
}
what is problem in this code??????????
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).
Last edited on
plz tell solution in code language
plz tell code
closed account (jwkNwA7f)
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.
Last edited on
plz plz plz......i have to submit this tommorow......plz plz plz only one code plz plz plz plz plz plz plz plz plz plz
closed account (jwkNwA7f)
We are not going to give you the code for the entire program. But, you can ask questions about each problem.
#include <iostream>

using namespace std;

int main ()
{
int n=1,smallest=0;

while ( n>0 )
{
cout<<"Enter a number"<<endl;
cin>> n;
}

smallest=n;

for (int i = n; i > 0 ; i++)
{
if(n>smallest)
smallest=n;
}

cout<< "smallest non-negative number is :" << smallest << endl;

return 0;
}
there is code......tell me mistake if u r not going to give me code
This is the same code like 1.5 hours ago you did nothing to improve it :(
closed account (jwkNwA7f)
@awais rana Daleth already told you some things to improve it here:
http://www.cplusplus.com/forum/beginner/110874/#msg605414
worst help i have ever seen......but God is there who will do my help from other source
@awais rana don't be rude, with your attitude you will never get help look at your posts
closed account (jwkNwA7f)
+1 for Chriscpp
Pages: 12