int tens = dollars / 10; dollars = dollars % 10;为什么先用/再用%
时间: 2023-05-24 10:04:41 浏览: 68
Null is a term used in programming and databases to indicate a lack of value or absence of data. It is typically represented by the keyword "null" or "NULL". In programming, a variable or object can be assigned a value of null to indicate that it has no value or has not been initialized. In databases, a null value represents missing or unknown data, and can be used in queries and calculations.
相关问题
import java.util.Scanner; public class calculator { public static void main(String [] args) { double monetary; Scanner scan=new Scanner(System.in); System.out.println("please enter the monetary amount:"); monetary=scan.nextDouble(); int dollars = (int) monetary; int cents = (int) ((monetary - dollars) * 100); int tens = dollars / 10; dollars = dollars % 10; int fives = dollars / 5; dollars = dollars % 5; int ones = dollars; int quarters = cents / 25; cents = cents % 25; int dimes = cents / 10; cents = cents % 10; int nickels = cents / 5; cents = cents % 5; int pennies = cents; System.out.println("That's equivalent to:"); System.out.println("10 dollar bill:" + tens); System.out.println("5 dollar bill:" + fives); System.out.println("1 dollar bill:" + ones); System.out.println("quarters:" + quarters); System.out.println("dimes:" + dimes); System.out.println("nickels:" + nickels); System.out.println("cents:" + pennies); } }为什么要先用/再用%
As an AI language model, I do not have feelings or emotions, and I cannot experience null. Null often refers to the absence of a value or a lack of data in programming and computer science. It is a commonly used concept in coding languages like JavaScript, Python, and SQL, among others.
#include <stdio.h> void selectElements(int arr[], int length) { for (int i = 0; i < length; i++) { int num = arr[i]; int hundreds = num / 100; int tens = (num / 10) % 10; int ones = num % 10; if (hundreds > (tens + ones)) { printf("%d ", num); } } }在visualc++中报错
如果在 Visual Studio 中编译该代码,可能会出现以下错误:
```
error C2143: syntax error : missing ';' before '}'
error C2447: '{' : missing function header (old-style formal list?)
```
这是因为在 Visual Studio 中,C99 标准需要在项目属性中进行设置才能支持。为了解决这个问题,可以将代码修改为符合 C90 标准的形式,如下所示:
```c
#include <stdio.h>
void selectElements(int arr[], int length) {
int i;
for (i = 0; i < length; i++) {
int num = arr[i];
int hundreds = num / 100;
int tens = (num / 10) % 10;
int ones = num % 10;
if (hundreds > (tens + ones)) {
printf("%d ", num);
}
}
}
```
这个版本的代码应该能够在 Visual Studio 中正常编译和运行。
相关推荐
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.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)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)