Computer Science, asked by SweetMystery, 2 months ago

Write a C program to print "Hello" ten times.
Also Explain Your Answer.

Spam=Report​

Answers

Answered by anindyaadhikari13
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.

}

  1. In this program, we can see that variable 'i' is initialised with value 1.
  2. In the test conditions, it is written - "i<=10". As long the test-conditions is true, the loop will iterate.
  3. 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