Print first m multiples of n in C#

王林
Release: 2023-09-13 14:21:10
forward
851 people have browsed it

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

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

int n = 6, m = 1;
Copy after login

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

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

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++;
      }
   }
}
Copy after login

Output

6 
 
12 
 
18 
 
24 
 
30 
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template