+ 1

I have a problem outputing (description) in C or C++ any one help?

Without using if only for loop... Output 1 6 2 7 3 8 4...

18th Nov 2021, 8:44 AM
Daniel Kagombe
Daniel Kagombe - avatar
5 Answers
+ 1
Daniel Kagombe I am terrible in C, but I can offer a C++ solution which you may adapt to C. #include <iostream> using namespace std; int main() { for(int i=1; i<6; i++){ cout<<i<<endl; cout<< i+5<< endl; } return 0; }
18th Nov 2021, 9:17 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 3
If you are struggling with this, then post your code attempt so we may assist further
18th Nov 2021, 8:59 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 2
Daniel Kagombe I am assuming you know how to construct a for loop, but don't understand how to create the pattern. I would the following in C++. Construct the for loop to repeat to your required number of iterations. In the body of your loop cout << iteration << endl << iteration +5 << endl;
18th Nov 2021, 8:59 AM
Rik Wittkopp
Rik Wittkopp - avatar
18th Nov 2021, 9:04 AM
Daniel Kagombe
Daniel Kagombe - avatar
+ 1
Thankyou it worked
18th Nov 2021, 4:43 PM
Daniel Kagombe
Daniel Kagombe - avatar