How can I get an output that repeats itself only using a printf statement. No loops involved (for, while etc) In C?
The output could look something like this:
- stackoverflow
- stackoverflow
- stackoverflow
- stackoverflow
- stackoverflow.
- etc
How can I get an output that repeats itself only using a printf statement. No loops involved (for, while etc) In C?
The output could look something like this:
Try this if you are afraid of recursion( very easy :) ):
#include <stdio.h>
void print(void)
{
printf("Stackoverflow");
}
int main(void)
{
print();
print();
print();
...
...
}
If you like recursion then try this:
#include <stdio.h>
void print(int n)
{
printf("Stackoverflow\n");
n--;
if (n > 0)
print(n);
}
int main(void)
{
int n;
Printf)"How many times do you want to print: ");
scanf ("%d", &n);
print(n);
}
Depending on what you regard as a loop, you can use goto
.
#include <stdio.h>
int main(void)
{
infinite_loop:
printf("stackoverflow\n");
goto infinite_loop;
}
#include <stdio.h>
#include <boost/preprocessor/repetition/repeat.hpp>
#define PROC(z, n, text) text
#define REP(str, n) BOOST_PP_REPEAT(n, PROC, str)
int main(){
REP( printf("Stackoverflow\n"); , 6);
return 0;
}