Write a C program to print "Hello" ten times.
Also Explain Your Answer.
Spam=Report
Answers
Answered by
21
Required Answer:-
Question:
- Write a C program to print "Hello" ten times.
Solution:
Here comes the program.
#include <stdio.h>
int main() {
for (int i=1;i<=10;i++)
printf("Hello. \n");
return 0;
}
Explanation:
- Using loop, this problem is solved. We can see that a loop is created that iterates ten times. Inside the loop, the statement - "printf("Hello \n")" is writen. As the loop iterates 10 times, so hello is displayed ten times.
Syntax of for loop:
for(initialisation; test-conditions; update-expression) {
statement or a set of statements.
}
- In this program, we can see that variable 'i' is initialised with value 1.
- In the test conditions, it is written - "i<=10". As long the test-conditions is true, the loop will iterate.
- In update-expression, value of 'i' is incremented by 1 otherwise the loop will not terminate and hello is printed infinite times.
Refer to the attachment for output ☑.
Attachments:
Similar questions
Math,
2 months ago
Math,
2 months ago
CBSE BOARD X,
2 months ago
Physics,
5 months ago
Social Sciences,
5 months ago
Biology,
11 months ago
Social Sciences,
11 months ago
Hindi,
11 months ago