- Write a program in C to print numbers between 1 to N without using semicolon and using recursion.
- How to print numbers between 1 to N without using semicolon and using while loop.
NOTE: printf function returns the number of characters printed on output device(screen).
C program to print natural numbers without using semicolon and using recursion
#include <stdio.h> int printNumber(int N){ if(N <= 10 && printf("%d ", N) && printNumber(N + 1)){ } } int main(){ if(printNumber(1)){ } }
Output
1 2 3 4 5 6 7 8 9 10
C program to print consecutive numbers without using semicolon and using while loop
#include <stdio.h> int printNumber(int N){ while (N++ <= 10 && printf("%d ", N-1)) { } } int main(){ if(printNumber(1)){ } }
Output
1 2 3 4 5 6 7 8 9 10