+ 1

Please help me to answer this question

i want enter tow numbers and create this output for example: user enter 4 and 9 for input the output this form 4 5 6 7 8 9 in c++ language

25th Jan 2017, 12:12 AM
mr.tajik
mr.tajik - avatar
9 Answers
+ 5
Well, if the first line always had one number in it, and the second line one more... then you could keep track of the number of numbers you have outputted to each line. In line one, after your number count equals one, you make a new line, and so on. There is probably a more efficient way to do this, but I don't know if it could take an input of any size in it. I hope this makes sense, and the best of luck to you!
25th Jan 2017, 12:28 AM
J.G.
J.G. - avatar
+ 5
void numbers(int a, int b) { int line = 1, count=0; for(int i=a; i<=b; ++i ) { cout <<i <<" "; count++; if (line ==count) { cout<<endl; line++; count=0; } } } Try something like this 👍 Edit: count=0
25th Jan 2017, 12:28 AM
Jafca
Jafca - avatar
+ 5
@Robobrine That works but it outputs: 1 2.3 4.5.6 7.8.9.10 11.12.13.14.15
25th Jan 2017, 12:38 AM
J.G.
J.G. - avatar
+ 4
void numbers(int a, int b){ for(int i = a, t = 0, m = 1; i <= b; i++, t--){ cout << i << " "; if(!t){ cout << endl; t = ++m; } } }
25th Jan 2017, 12:34 AM
Robobrine
Robobrine - avatar
+ 2
thanks for all😘
25th Jan 2017, 12:37 AM
mr.tajik
mr.tajik - avatar
+ 1
Wait, what would happen if the user enters 4 and 7? 4 5 6 7 or something else?
25th Jan 2017, 12:15 AM
Robobrine
Robobrine - avatar
+ 1
yes,the output is this form 4 5 6 7
25th Jan 2017, 12:18 AM
mr.tajik
mr.tajik - avatar
+ 1
i write this answer #include <iostream> using namespace std; void numbers (int,int); int main() { int a,b; cout <<"enter 2 numbers"<<endl; cin>>a>>b; numbers (a,b); return 0; } void numbers(int a,int b) { for(int i=a;i<=b;i++) cout<<i<<endl; } but not work
25th Jan 2017, 12:20 AM
mr.tajik
mr.tajik - avatar
0
Hey if you need them all Multipled then hear 4x9=36 36x56=2016 2016=789=159,062,4
25th Jan 2017, 1:00 AM
Dillon H
Dillon H - avatar