In this tutorial you will learn about the C Program to Print Hello World Multiple Times and its application with practical example.
In this tutorial, we will learn to create a program to print “Hello World” multiple times using for loop C programming language.You can also use While Loop, or Do While to do the same task.
Prerequisites
Before starting with this tutorial we assume that you are best aware of the following C programming topics:
- C printf
- C for loop
- C while loop
- C do while loop
Program to Print Hello World Multiple Times
In this program we will print “Hello World” multiple time using for loop. We would first declared and initialized the required variables. Next, we would prompt user to input number of time you want print “Hello World”. Later we will print same “Hello World” string for number of time input by user.
1 2 3 4 5 6 7 8 9 10 11 12 |
#include<stdio.h> int main() { int n,i; printf("Enter a number:"); scanf("%d",&n); for(i=1;i<=n;i++) { printf("Hello World\n"); } return 0; } |
Output:-
In the above program, we have first declared and initialized a set variables required in the program.
- n = take number by user to print message.
- i = iterator to loop through.
In the next statement user will be prompted to enter a number which will be assigned to variable ‘n’. Now we will loop through the iterator ‘i’. Inside the for loop we have print statement to print “Hello World. This will be repeated until it print “Hello World” required number of times.