0
how to print 1 to 100 without loop,iteration,goto.
2 Antworten
+ 6
So you use a concept of recursion if you do not want to use a loop. Pretty much the function calls itself again until it gets to the point to break it.
Here is example code
#include <iostream>
using namespace std;
void count(int start) {
if(start <= 100) {
cout << start << endl;
start++;
count(start);
}
}
int main() {
int start = 1;
count(start);
}
0
trick: use foreach "function"
#include <iostream>
#include <numeric>
#include <algorithm>
using namespace std;
int main() {
int oneToHundred[100];
iota(oneToHundred, oneToHundred + 100, 1);
for_each(oneToHundred, oneToHundred + 100, [](int i){cout << i << endl;});
return 0;
}