Input: N = 10
Output: 10 9 8 7 6 5 4 3 2 1
Input: N = 5
Output: 5 4 3 2 1
- Use static variable to initialise the given number N.
- Print the number N and decrement it.
- Call the main() function recusrsively after above step.
Below is the implementation of the above approach:
10 9 8 7 6 5 4 3 2 1
Time Complexity: O(N), where N is the given number.
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Is it fine to write "void main()" or "main()" in C/C++?
- Difference between "int main()" and "int main(void)" in C/C++?
- C/C++ program to print Hello World without using main() and semicolon
- Can main() be overloaded in C++?
- What does main() return in C and C++?
- Executing main() in C/C++ - behind the scene
- Functions that are executed before and after main() in C
- How can we write main as a class in C++?
- How to change the output of printf() in main() ?
- How to write a running C code without main()?
- return statement vs exit() in main()
- Print "Hello World" with empty or blank main in C++
- How to print "GeeksforGeeks" with empty main() in C, C++ and Java?
- How to call some function before main() function in C++?
- Calling virtual methods in constructor/destructor in C++
- C program to print a string without any quote (singe or double) in the program
- Hello World Program : First program while learning Programming
- C Program for Program to find area of a circle
- Lex Program to remove comments from C program
- C Program for Program for array rotation
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.