Algorithm
[Programmers] 부족한 금액 계산하기
Y06
2022. 3. 14. 19:52
[문제]
https://programmers.co.kr/learn/courses/30/lessons/82612
코딩테스트 연습 - 부족한 금액 계산하기
새로 생긴 놀이기구는 인기가 매우 많아 줄이 끊이질 않습니다. 이 놀이기구의 원래 이용료는 price원 인데, 놀이기구를 N 번 째 이용한다면 원래 이용료의 N배를 받기로 하였습니다. 즉, 처음 이
programmers.co.kr
[풀이]
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
long long solution(int price, int money, int count) {
long long answer = 0;
int n=0;
for(int i=1; i<=count; i++){
n = price*i;
answer += n;
}
if(answer > money) return answer-money;
else return 0;
return answer;
}
int main(){
int price=0;
int money=0;
int count=0;
scanf("%d %d %d", &price, &money, &count);
solution(price,money,count);
}