Friday 14 February 2014

Print n time Without Loop

How to print any thing n times Without Using any LOOP :

this is very easy & very common question : ask to check your recursion Programming  Basics .



It is really very easy : you just have to make a simple function

I gave you source code for this program in C & Python I hope it definitely  help you  if you are unable to get it .




# Python 3 Code :



 def repeat(n):  
  a=n  
  print("Hindustan") # it has to print  
  a=a-1 # decresing index  
  if(a==0): # condition to break  
    exit  
  else:  
    repeat(a) # recursion  
 n=int(input( "No of time you want to print : "))  
 repeat(n)  

# C code


 #include<stdio.h>  
 #include<stdlib.h>  
 void recursion(int n)  
 {  
      printf("this is to print \n");  
      n=n-1;  
      if(n==0)  
        exit(0);  
      else  
        recursion(n);  
 }  
 main()  
 {  
      int n;  
      printf("no of time you want to return : ");  
      scanf("%d",&n);  
      recursion(n);  
 }  

Have a nice day :P

No comments:

Post a Comment

THANKS FOR UR GREAT COMMENT

Blogger Widgets