C program to print 1 to 100 without using any loop or conditional operator ( C Interview question - 3)
Write a C program to print numbers from 1 to 100?
Conditions : 1 . You cannot use loops(for, while)
2. You cannot use conditional operator
3. No goto statement
Solution :
#include <stdio.h>
void print()
{
static int num = 0;
num++;
printf("%d\n", num);
if ( num < 100)
print();
}
int main()
{
print();
return 0;
}
Conditions : 1 . You cannot use loops(for, while)
2. You cannot use conditional operator
3. No goto statement
Solution :
#include <stdio.h>
void print()
{
static int num = 0;
num++;
printf("%d\n", num);
if ( num < 100)
print();
}
int main()
{
print();
return 0;
}
Comments
Post a Comment