0

Write cpp program that print from 1 to 100 using recursion ?

7th Jun 2017, 6:06 AM
Omar Abdullah
Omar Abdullah - avatar
3 ответов
+ 13
@Omar That is iteration, not recursion. Recursion is something like, void num(int i) { std::cout << i; if (i < 100) { num(++i); } } int main() { num(1); }
7th Jun 2017, 6:21 AM
Hatsy Rei
Hatsy Rei - avatar
+ 1
Thanks hatsy . But why when u call the function in if statment the argumnt "pre-increment" ?
7th Jun 2017, 8:51 PM
Omar Abdullah
Omar Abdullah - avatar
0
Is it like this ? \/\/\/ #include <iostream> using namespace std; void num(){ for(int i=1;i<=100;i++){ cout<<i<<endl; } } int main() { num(); }
7th Jun 2017, 6:12 AM
Omar Abdullah
Omar Abdullah - avatar