내적
https://programmers.co.kr/learn/courses/30/lessons/70128
코딩테스트 연습 - 내적
길이가 같은 두 1차원 정수 배열 a, b가 매개변수로 주어집니다. a와 b의 내적을 return 하도록 solution 함수를 완성해주세요. 이때, a와 b의 내적은 a[0]*b[0] + a[1]*b[1] + ... + a[n-1]*b[n-1] 입니다. (n은 a, b의
programmers.co.kr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <string> | |
#include <vector> | |
using namespace std; | |
int solution(vector<int> a, vector<int> b) { | |
int answer = 0; | |
for(int i = 0; i < a.size(); ++i) | |
{ | |
answer += a[i] * b[i]; | |
} | |
return answer; | |
} |
반응형
'자료구조 와 알고리즘 > 프로그래머스' 카테고리의 다른 글
음양 더하기 (0) | 2022.05.08 |
---|---|
K번째수 (0) | 2022.05.08 |
두 개 뽑아서 더하기 (0) | 2022.05.08 |
이상한 문자 만들기 (0) | 2022.05.08 |
자릿수 더하기 (0) | 2022.05.08 |