游客 Signup | Login
中文 | En

2441 - 【入门】求任意三位数各个数位上数字的和

对于一个任意的三位自然数X,编程计算其各个数位上的数字之和S。

Input

输入一行,只有一个整数x(100<=x<=999)

Output

输出只有一行,包括1个整数

Examples

Input

123

Output

6

Solution C

#include<stdio.h>
int main()
{
int a,b,c,d;
scanf("%d",&a);
b=a/100;
c=(a%100)/10;
d=a%10;
printf("%d",b+c+d);
}

Solution C++

#include <iostream>
using namespace std;
int main()
{
  int a,b,c,d,x;
  cin>>a;
  b=a%10;
  c=a/10%10;
  d=a/100%10;
  x=b+c+d;
  cout<<x;
  return 0;
}
Time Limit 1 second
Memory Limit 128 MB
Discuss Stats
上一题 下一题