Computer Science, asked by williambarnes, 1 year ago

Write a program that uses a while loop to calculate and print the multiples of 3 from 3 to 21. Your program should print each number on a separate line.

Sample Run

3
6
9
12
15
18
21

Answers

Answered by digi18
5

public class Multiple{

public static void main(String[ ] args) {

int i = 1 ;

while(int i<8){

int j = 3*i ;

System.Out.Println( j ) ;

i++ ;

}

}

}

Thanks

Answered by AskewTronics
2

The c- program for the above is as follows:

Explanation:

#include <stdio.h> // header file inclusion.

int main() // main function declaration.

{

  int print=3; // variable declared to print the multiple of 3

  while(print<22) // while loop which terminates when the 21 is printed.

  {

       printf("%d\n",print);// print the multiple of 3.

       print=print+3; // calculate the multiple of 3 for every iteration.

   }

   return 0; // return statement.

}

Output:

  • The above program gives output in that format in which the question demands. It prints a table of 3 from 3 to 21 in a separate line.

Code explanation:

  • The above program executes the while loop body until the print value is not 21.
  • It prints every value of the print variable after adding 3 on its which make the table because 3\times2=6 which also comes from 3+3.

Learn More:

  • C-Language : brainly.in/question/610076

Similar questions