Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 |
Tags
- cleancode
- 플라스크
- 한빛미디어
- 코테
- 예리님
- 리액트
- 원티드
- 개발스터디
- AWS
- 파이썬
- fluentpython
- flask
- 환경변수
- 전문가를위한파이썬
- 패스트캠퍼스
- 개발
- 한빛
- React
- mongodb
- 코드프레소
- 프리온보딩
- Python
- 깃
- 위코드
- codepresso
- git
- pyladiesseoul
- 스터디
- env
- pyladies
Archives
- Today
- Total
개발자가 내팔자
[Programmers] 자릿수 더하기 Python / Java / JavaScript / C / C++ 본문
Python
def solution(n):
answer = 0
while (n > 0):
answer += n % 10
n = n // 10
return answer
Java
import java.util.*;
public class Solution {
public int solution(int n) {
int answer = 0;
while (n > 0) {
answer += n % 10;
n = n / 10;
}
return answer;
}
}
JavaScript
function solution(n)
{
let answer = 0;
while (n) {
answer += parseInt(n % 10);
n = parseInt(n / 10);
}
return answer;
}
C
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
int solution(int n) {
int answer = 0;
while (n) {
answer += n % 10;
n /= 10;
}
return answer;
}
C++
#include <iostream>
using namespace std;
int solution(int n)
{
int answer = 0;
while (n) {
answer += n % 10;
n /= 10;
}
return answer;
}
'Algorithms' 카테고리의 다른 글
[Programmers] 문자열 내 마음대로 정렬하기 Python / Java (0) | 2022.08.08 |
---|---|
[Programmers] 두 개 뽑아서 더하기 Python / Java (0) | 2022.08.08 |
[Programmers] 자연수 뒤집어 배열로 만들기 Python / Java / JavaScript / C (0) | 2022.08.05 |
[BOJ] 백준 1780 종이의 개수 Python (0) | 2022.07.30 |
[BOJ] 백준 1074 Z Python (0) | 2022.07.29 |
Comments