Home >Backend Development >C#.Net Tutorial >Print first m multiples of n in C#

Print first m multiples of n in C#

王林
王林forward
2023-09-13 14:21:10914browse

在 C# 中打印 n 的前 m 倍数

To print m multiples of n, first set the values ​​of m and n -

int n = 6, m = 1;

Now loop through the values ​​of m, incrementing it and multiplying by n on each iteration -

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

Let’s 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 

The above is the detailed content of Print first m multiples of n in C#. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete