Printing a String Multiple Times in C Programming


This program is written in the C programming language, and it is used to print the string "Hai" a specified number of times. The program starts by including the standard input/output header file, "stdio.h". Then, the main() function is defined. Inside the main function, two variables are declared: "n" for the number of times the string should be printed and "i" is used as a counter variable in the for loop.

The program then prompts the user to enter a number using the printf() function and stores the value in the "n" variable using the scanf() function. The for loop is then used to repeatedly execute the code inside the loop for the number of times specified by the user. The for loop starts with "i" initialized to 1, and the loop continues until "i" is less than or equal to "n".

The printf() function inside the loop is used to print the string "Hai" on the screen each time the loop is executed. The value of "i" is incremented by 1 in each iteration of the loop using the increment operator (++) so that the loop will eventually terminate when "i" reaches the value of "n". Finally, the program is exited by returning 0 from main.

Source Code

#include<stdio.h>     
int main()
{
    int n,i;
    printf("\nEnter the limit:");
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        printf("\nHai");
    }
   return 0;
}
To download raw file Click Here

Output

Enter the Limit : 5
Hai
Hai
Hai
Hai
Hai

List of Programs


Sample Programs


Switch Case in C


Conditional Operators in C


Goto Statement in C


While Loop Example Programs


Looping Statements in C

For Loop Example Programs


Array Examples in C

One Dimensional Array


Two Dimensional Array in C


String Example Programs in C


Functions Example Programs in C