Tuesday, May 13, 2008 at 10:41 PM |  

Print Hello, n times, taken as input from terminal, without using any loop


 

#include<stdio.h>

#include<conio.h>

int a,b,i=0;

void print(int );

void main()

{

clrscr();

printf("How many times do you want to print Hello?");

scanf("%d",&a);

print(a);

getch();

}

void print (int b)

{

if(i!=a && i<a)

{

printf("\n Hello!");

i++;

print(a); /*FUNCTION CALLED ITSELF WITHIN ITS OWN BODY*/

}

}


 

EXPLANETION: - I here use recursive function
to solve this very problem. Recursive function is one type of function which can call itself within its own body until some conditions are fulfilled. Here integer variables a, b & i are declared as global variable.

Posted by Satyabrota

0 comments: