题面
Complete the definition of the function, which computes the sum of every digit in an integer.
输入格式
You shouldn't care about the details of the input and output, but the parameter you received must be an integer.
输出格式
You shouldn't care about the details of the input and output.
提示
You need to complete the definition of a function that takes an integer x
and returns an integer representing the sum of each digit of x
.
对于 C/C++,函数原型如下:
/**
* computes the sum of every digit in an integer
* @param x the integer you need to process
* @return the sum of every digit of x
*/
int sumOfDigits(int x);
判题程序如下:
#include<stdio.h>
/**
* computes the sum of every digit in an integer
* @param x the integer you need to process
* @return the sum of every digit of x
*/
int sumOfDigits(int);
/* 你的代码将会被嵌入在这个地方 */
int main() {
/* 输入格式和细节隐藏不表 */
printf("%d\n",theSumOfDigitsInTheInteger(x));
return 0;
}
如果你需要,你可以在提交代码的任意位置使用 #include
语句导入任何你需要的库。
对于 Java,函数原型如下:
/**
* computes the sum of every digit in an integer
* @param x the integer you need to process
* @return the sum of every digit of x
*/
private static int sumOfDigits(int x);
判题程序如下:
public class Main {
/* 你的代码将会被嵌入在这个地方 */
public static void main(String[] args) {
/* 输入格式和细节隐藏不表 */
System.out.println(sumOfDigits(n));
}
}
如果你需要,你可以使用 java.lang
包中的任何类,但是不应该(其实也不需要)导入其他的包,即使是 java.util
包。