본문 바로가기

공부/코딩테스트

[프로그래머스,C언어] 원소들의 곱과 합


문제

 

 


풀이

#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>

// num_list_len은 배열 num_list의 길이입니다.
int solution(int num_list[], size_t num_list_len) 
{
    int answer = 0;
    int loop;
    int a = 0;
    int b = 0;
    
    for(loop = 0; loop <num_list_len; loop++)
    {
        a+=num_list[loop];        
    }
    
    b = num_list[0];
    for(loop = 1; loop <num_list_len; loop++)
    {
        b*=num_list[loop];
    }

    a = pow(a,2);

        if(a>b)
        {
            answer = 1;
        }
        else
        {
            answer = 0;            
        }

    
    
    return answer;
}

'공부 > 코딩테스트' 카테고리의 다른 글

[프로그래머스,C언어] 공배수  (0) 2024.03.16
[프로그래머스] 문자열 출력하기  (0) 2024.03.04