+ 5
How to print 1 2 3 4 5 6 7 8 9 10 9 8 7 6 5 4 3 2 1 in C++ by using only one loop?
13 Respostas
+ 1
Here you can check my code for you
https://code.sololearn.com/cM22opxG0CyH/?ref=app
+ 16
ok sorry I didn't paid attention! no reason to downvote like this..
be quiet bros!
what about this?
https://code.sololearn.com/cDA4szWAp6Xy/?ref=app
+ 13
for(int i = 1; i < 20; i++){
cout<<(i > 10) ? 20-i : i;
}
+ 11
and also.. who downvotes should enlight us whit a good answer!
+ 11
@aztecco good, very good
+ 11
@aztecco it's probably a crazy man))
+ 11
You could always do it with no loops.
https://code.sololearn.com/cJjsg7x4c6ST/?ref=app
+ 10
thank you @Robert! but I'm not crazy.. or not at all lol
+ 9
@aztecco They require only one loop, but you wrote with two loops, try again
+ 4
#include <iostream>
using namespace std;
int main() {
int x; int y = 9;
for(int x = 1; x < 20; x++) {
if (x <= 10) {
cout << x << " ";
}
else {
cout << y-- <<" " ;
}
}
}
// Output: 1 2 3 4 5 6 7 8 9 10 9 8 7 6 5 4 3 2 1
+ 3
a@a@a although is related you should make your own question.
Btw mine in C
i;f(){for(i=8;i--;)printf("%d %d ",9-i,i+2);}
https://code.sololearn.com/c4CKbw0lM3gh/?ref=app
+ 1
How toPrint FOR loop.
Output: 2 9 3 8 4 7 5 6 6 5 7 4 8 3 9 2
- 4
use nested For loops