How to print a name multiple times without loop statement using C language?


Problem

Try to print a name 10 times without using any loop or goto statement in C programming language.

Solution

Generally, looping statements are used to repeat the block of code until condition is false.

Example1

In this program, we are trying to print a name 10 times without using loop or goto statements.

 Live Demo

#include <stdio.h>
void printname(char* name,int count){
   printf("%03d : %s
",count+1,name);    count+=1;    if(count<10)       printname(name,count); } int main(){    char name[50];    printf("
Enter you name :");    scanf("%s",name);    printname(name,0);    return 0; }

Output

Enter you name :tutorialspoint
001 : tutorialspoint
002 : tutorialspoint
003 : tutorialspoint
004 : tutorialspoint
005 : tutorialspoint
006 : tutorialspoint
007 : tutorialspoint
008 : tutorialspoint
009 : tutorialspoint
010 : tutorialspoint

Example 2

Below is the program to print your name 10 times using any loop or goto statement −

 Live Demo

#include <stdio.h>
int main(){
   char name[50],i;
   printf("
Enter you name :");    scanf("%s",name);    for(i=0;i<10;i++){       printf("%s
",name);    }    return 0; }

Output

Enter you name :TutorialsPoint
TutorialsPoint
TutorialsPoint
TutorialsPoint
TutorialsPoint
TutorialsPoint
TutorialsPoint
TutorialsPoint
TutorialsPoint
TutorialsPoint
TutorialsPoint

Updated on: 09-Mar-2021

6K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements