Print first m multiples of n in C#


To print m multiples of n, first set the value of m and n −

int n = 6, m = 1;

Now loop through the value of m, increment it and multiply with n on every iteration −

while (m <= 5) {
   // multiply n*m
   m++;
}

Let us see the complete code −

Example

Live Demo

using System;

public class Demo {
   public static void Main() {
      int n = 6, m = 1;
      while (m <= 5) {
		   Console.WriteLine(" {0} 
", n * m); m++; } } }

Output

6 
 
12 
 
18 
 
24 
 
30 

Samual Sam
Samual Sam

Learning faster. Every day.

Updated on: 30-Jul-2019

504 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements