카타 7급 Beginner Series #3 Sum of Numbers

1 C[ | ]

int get_sum(int a , int b) {
  if( a == b ) return(a);
  int min = a;
  int max = b;
  if( a > b ) {
    max = a;
    min = b;
  }
  int sum = 0;
  for(int i=min; i<=max; i++) sum+=i;
  return sum;
}
int get_sum(int a , int b) {
  return ((a+b) * 0.5)*(abs(a-b) + 1);
}
int get_sum(int a , int b) {
  if(a == b) return a;
  int max = a > b ? a : b;
  int min = a < b ? a : b;
  int sum = 0;
  for(int i = min; i <= max; i++) sum += i;
  return sum;
}
int get_sum(int a , int b) {
  if (b < a) {
    a ^= b;
    b ^= a;
    a ^= b;
  }
  return (a+b)/2.0 * (b-a+1);
}

2 R[ | ]

get_sum <- function(a, b){
  sum(a:b)
}
get_sum <- function(a, b){
  if( a == b ) return(a)
  sum(a:b)
}
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}