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;
}

Comments

Popular posts from this blog

bb.utils.contains yocto

Difference between RDEPENDS and DEPENDS in Yocto

make config vs oldconfig vs defconfig vs menuconfig vs savedefconfig