C program to print your name 10 times without using any loop or goto statement

In this program, we will learn how to print any message without using any loop or goto statement? . Here we will use recursionrecursion is a process by which a function calls itself.
By using recursion we can print any message N times.

Source Code

/*program to print your name 10 times without 
using any loop or goto statement*/
 
#include <stdio.h>
void printName(char* name,int count) 
{ 
    printf("%03d : %s\n",count+1,name); 
    count+=1; 
    if(count<10) 
        printName(name,count); 
} 
int main() 
{ 
    char name[50];  
    printf("\nEnter you name :"); 
    scanf("%s",name); 
    printName(name,0); 
    return 0; 
}

Output

Enter you name :C-Language 
001 : C-Language 
002 : C-Language 
003 : C-Language 
004 : C-Language 
005 : C-Language 
006 : C-Language 
007 : C-Language 
008 : C-Language 
009 : C-Language 
010 : C-Language

Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.