문제
정수 배열 numbers가 매개변수로 주어집니다. numbers의 원소 중 두 개를 곱해 만들 수 있는 최댓값을 return하도록 solution 함수를 완성해주세요.
솔루션
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
// numbers_len은 배열 numbers의 길이입니다.
int solution(int numbers[], size_t numbers_len) {
int answer = 0;
int max = numbers[0]*numbers[1];
for(int i = 0; i < numbers_len-1; i++)
for(int j = i+1; j < numbers_len; j++)
{
if(numbers[i]*numbers[j] > max)
max = numbers[i]*numbers[j];
}
answer = max;
return answer;
}
https://school.programmers.co.kr/learn/courses/30/lessons/120862
'프로그래머스코딩테스트연습풀이 > C언어' 카테고리의 다른 글
[프로그래머스/C언어] 팩토리얼 (0) | 2023.08.03 |
---|---|
[프로그래머스/C언어] 숨어있는 숫자의 덧셈 (1) (0) | 2023.08.03 |
[프로그래머스/C언어] 삼각형의 완성조건 (1) (0) | 2023.08.03 |
[프로그래머스/C언어] 암호 해독 (0) | 2023.08.03 |
[프로그래머스/C언어] 인덱스 바꾸기 (0) | 2023.08.03 |