쌓고 쌓다
[프로그래머스] 내적 C++ 풀이 본문
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
전체 코드
#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;
}
'알고리즘 > 프로그래머스' 카테고리의 다른 글
[프로그래머스] 완주하지 못한 선수 C++ 풀이 (0) | 2022.06.28 |
---|---|
[프로그래머스] 소수 만들기 C++ 풀이 (0) | 2022.06.27 |
[프로그래머스] 음양 더하기 C++ 풀이 (0) | 2022.06.27 |
[프로그래머스] 없는 숫자 더하기 C++ 풀이 (0) | 2022.06.27 |
[프로그래머스] 크레인 인형뽑기 게임 C++ 풀이 (0) | 2022.06.27 |
Comments