546A题目网址
题目解析
1.输入 k(成本),n(拥有的钱),w(要买的个数),输出还需要向朋友借多少钱?
举例:
输入:
3 17 4
输出:
13
2.注意:
1)第i个,需要i*k个价钱,所以需要使用for循环运算花费
2)当拥有的钱足够买时,不需要借钱,输出为0
代码
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{int k,n,w,count=0,need=0;scanf("%d %d %d",&k,&n,&w);for(int i=1;i<=w;i++){count+=i*k;}if(count-n>0){need=count-n;}elseneed =0;printf("%d",need);system("pause");getchar();return 0;
}