Print first m multiples of n in C#

CsharpProgrammingServer Side Programming

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 ", n * m);
         m++;
      }
   }
}

Output

6 
 
12 
 
18 
 
24 
 
30 
raja
Published on 31-Aug-2018 12:08:58
Advertisements