c++ 函数题目!

来源:百度知道 编辑:UC知道 时间:2024/05/16 04:39:37
请教难题!
目前人民币有以下几种面值(不包括角和分);
1元,2元,5元,10元,20元,50元,100元
编写一个函数计算金额"X"需要多少张面值为n元的纸币.在函数中输入一个金额值,调用该函数,计算组成该金额最少需要多少张纸币.

求解!我做了好多次都有bug!
我只想用#include "stdio.h" 来做,你们用的那些函数我都不懂,希望能够简单点,让我更加明白,谢谢,再提高20分悬赏!

#include "stdio.h"
#include "conio.h"

unsigned int fun(unsigned int x)
{
unsigned int r = 0;
r += (x/100);
x %= 100;
r += (x/50);
x %= 50;
r += (x/20);
x %= 20;
r += (x/10);
x %= 10;
r += (x/5);
x %= 5;
r += (x/2);
x %= 2;
r += x;
return r;
}

int main()
{
unsigned int x;
printf("X=");
scanf("%u",&x);
printf("\n%u",fun(x));
getch();
return 0;
}

c++
钱能的课程里都有的

#include<iostream.h>
void main()
{
int x;
int hun=0,fty=0,tty=0,ten=0,five=0,two=0,one=0;
cout<<"请输入金额:";
cin>>x;
cout<<endl;
cout<<"最少需要的纸币为:"<<endl;
if(x/100>0)
{
hun=x/100;
cout<<"100元币:"<<hun<<"张"<<