There are many ways to print numbers without using any loop conditions such as for(), while(), do while(). Few ways are,
1. Using recursive functions
2. Using recursive main functions
3. Using goto statement
4. Using printf statement (But it’s not preferred for printing big numbers)
1. Using recursive functions:
#include
int recursive(int value)
{
int i;
printf(“%d\n”, value);
i = value + 1;
if (i > 500)
return 0;
recursive(i);
}
int main()
{
recursive(1);
return 0;
}
2. Using recursive main functions:
#include
int main()
{
static int i = 1;
if (i <= 500)
{
printf(“%d\n”, i++);
main();
}
return 0;
}
3. Using goto statement:
#include
int main()
{
int i = 0;
Start: i = i + 1;
printf(“%d\n”, i);
if (i < 500)
goto Start;
return 0;
}
4. Using printf statement (But it’s not preferred for printing big numbers):
You can use simple C program using printf() function to print the numbers as many times you want.
There are many ways to print numbers without using any loop conditions such as for(), while(), do while(). Few ways are,
1. Using recursive functions
2. Using recursive main functions
3. Using goto statement
4. Using printf statement (But it’s not preferred for printing big numbers)
1. Using recursive functions:
2. Using recursive main functions:
3. Using goto statement:
4. Using printf statement (But it’s not preferred for printing big numbers):
You can use simple C program using printf() function to print the numbers as many times you want.
need an explanation for this answer? contact us directly to get an explanation for this answer