输出1~100中前5个是13的倍数的数字。 输入格式: 无输入。 输出格式: 换行输出。用javafor
时间: 2024-05-29 09:08:57 浏览: 34
int count = 0;
for(int i=1; i<=100; i++){
if(i%13==0){
count++;
System.out.println(i);
if(count==5){
break;
}
}
}
相关问题
输出1-100中是13的倍数的数字用java
语言怎么写?
可以这样写:
public class ThirteenMultiples {
public static void main(String[] args) {
for (int i = 1; i <= 100; i++) {
if (i % 13 == 0) {
System.out.print(i + " ");
}
}
}
}
用c语言编写请编写程序,实现对用户输入的 n (n<100)求出1~n的最小公倍数。 输入格式: 6 输出格式: 60
好的,以下是使用 C 语言编写的程序,实现对用户输入的 n (n<100)求出1~n的最小公倍数:
```c
#include <stdio.h>
int gcd(int a, int b) {
while (b) {
int tmp = a % b;
a = b;
b = tmp;
}
return a;
}
int lcm(int a, int b) {
return a * b / gcd(a, b);
}
int get_lcm(int n) {
int res = 1;
for (int i = 2; i <= n; i++) {
res = lcm(res, i);
}
return res;
}
int main() {
int n;
scanf("%d", &n);
printf("%d", get_lcm(n));
return 0;
}
```
程序的核心部分与 Python 版本相似,使用了两个函数分别求最大公约数和最小公倍数,然后遍历1到n的所有数,求出它们的最小公倍数,最后返回1到n的最小公倍数。
希望这个程序能够帮到您!
相关推荐
![java](https://img-home.csdnimg.cn/images/20210720083646.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)