用C++编程实现一个函数,输入任意面值人民币时,输入按面值100、50、20、10、5、2、1兑换的结果。

作者&投稿:赞食 (若有异议请与网页底部的电邮联系)
利用ARM指令比较两个数大小,要求用函数调用。~

假设两个32位数分别在 R0, R1
则:

CMP R0, R1
BCS LOC_01 ;无符号数大于或等于
MOV R0, #0x0 ;如果 R0 < R1 , 返回 R0 = 0
RET
LOC_01
MOV R0, #0x1 ;如果 R0 >= R1 ,返回 R0 = 1
RET

另外, ARM 汇编中没有 RET 指令,所以:
RET 要用到宏,否则无法编译,如下:
macro
RET
DCB0xE, 0xF0, 0xA0, 0xE1
mend

#include

void main()
{
int a,b,c,d,e,f;
for(a=0;a<=2;a++)
for(b=0;b<=5;b++)
for(c=0;c<=10;c++)
for(d=0;d<=20;d++)
for(e=0;e<=50;e++)
for(f=0;f<=100;f++)
if(a*50+b*20+c*10+d*5+e*2+f==100)
printf("%d,%d,%d,%d,%d,%d
",a,b,c,d,e,f);
}

运行结果:
1,0,1,0,6,28
1,0,1,0,7,26
1,0,1,0,8,24
1,0,1,0,9,22
1,0,1,0,10,20
1,0,1,0,11,18
1,0,1,0,12,16
1,0,1,0,13,14
1,0,1,0,14,12
1,0,1,0,15,10
1,0,1,0,16,8
1,0,1,0,17,6
1,0,1,0,18,4
1,0,1,0,19,2
1,0,1,0,20,0
1,0,1,1,0,35
1,0,1,1,1,33
1,0,1,1,2,31
1,0,1,1,3,29
1,0,1,1,4,27
1,0,1,1,5,25
1,0,1,1,6,23
1,0,1,1,7,21
1,0,1,1,8,19
1,0,1,1,9,17
1,0,1,1,10,15
1,0,1,1,11,13
1,0,1,1,12,11
1,0,1,1,13,9
1,0,1,1,14,7
1,0,1,1,15,5
1,0,1,1,16,3
1,0,1,1,17,1
1,0,1,2,0,30
1,0,1,2,1,28
1,0,1,2,2,26
1,0,1,2,3,24
1,0,1,2,4,22
1,0,1,2,5,20
1,0,1,2,6,18
1,0,1,2,7,16
1,0,1,2,8,14
1,0,1,2,9,12
1,0,1,2,10,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<stdlib.h>
#include <iostream>
// 在这里定义货币面值, 可任意修改和添加, 但是最后一个必须为1
int money[] = { 100, 50, 20, 10, 5, 2, 1 };

int main()
{
int input;
std::cout << "输入数值" << endl;
std::cin >> input;
for(int i = 0; input != 0 && i != sizeof(money)/sizeof(int); input %= money[i], ++i)
if(input/money[i] != 0)
std::cout << money[i] << "面值" << input/money[i] << "张" << std::endl;
system("pause");
return 0;
}
//-------------------------------------------------------
输入数值
868
100面值8张
50面值1张
10面值1张
5面值1张
2面值1张
1面值1张
请按任意键继续. . .

#include <iostream>
using namespace std;

int main(void)
{
printf("请输入面值:\n");
int val = 0;
while (cin>>val)
{
if ((val/100)!=0)
{
cout << "100元" << val/100 <<"张 " << flush;
}
if (((val%=100)/50)!=0)
{
cout << "50元" << val/50 << "张 " << flush;
}
if (((val%=50)/10)!=0)
{
cout << "10元" << val/10 << "张 " << flush;
}

if (((val%=10)/5)!=0)
{
cout << "5元"<< val/5 <<"张 "<< flush;
}

if (((val%=5)/2)!=0)
{
cout << "2元" << val/2 << "张 " << flush;
}

if (((val%=2))!=0)
{
cout << "1元" << val << "张 "<< flush;
}
cout <<endl;
}

return 0;
}

最后输入ctrl+x结束

#include<iostream>
using namespace std;

void main()
{
int m;
int i;
cout<<"要找的钱是:";
cin>>m;
int T[7] ={100,50,20,10,5,2,1}; //货币种类
int coins[7] = {0};
for(i = 0; i < 6; )
{
if(m < T[i])
{
i++;
continue;
}
while(m >= T[i])
{
m -= T[i];
coins[i]++;
}
i++;

}

for(i = 0; i < 7; i++)
if(coins[i] != 0)
cout<<T[i]<<"元有"<<coins[i]<<"张"<<", ";

cout<<endl;
}

要找的钱是:868
100元有8张, 50元有1张, 10元有1张, 5元有1张, 2元有1张,
Press any key to continue

void change(int money,int *c){
int d[]={100,50,20,10,5,2,1};
for(int i=0;i<sizeof(d)/sizeof(d[0]);i++){
if(money>=d[i]){
c[i]=money/d[i];
money-=c[i]*d[i];
}
else{c[i]=0;}
}
}


C语言,编程实现:输出以下图形
include <stdio.h>#include <math.h>int main(){int i,j;for(i=-2; i<=2; i++){for( j=2; j>=-2; j--){if(abs(i)+abs(j)<=2)printf("*");elseprintf(" ");}printf("\\n");}return 0;} 把整个图形看成直角坐标系 ...

c语言 给一个不多于5位的正整数 用C语言写出
第一种方法代码:include <stdio.h> include <math.h> int main(){ int a,b,c,d;int count = 1;printf("请输入一个不多于5位的正整数:");scanf("%d",&a);c = a;printf("逆序:\\n");while(c \/ 10 != 0){ count++;b = c % 10;printf("%d\\n",b);c = c \/ 10;} ...

请问如何用C语言编程编写一个实现加法的函数,例如y=3x+1这个函数。
include <stdio.h>double f(double x){return(x*3+1);}void main(){double x;scanf("%lf",&x);printf("%lf",f(x));}

用大一知识做c语言 编程实现,输入一个正整数n,计算(1+2)+(2+3)+...
include <stdio.h>int main(void) { int i, sum = 0; printf("Enter an positive integer: "); scanf("%d", &i); while (i > 1) { sum += ((i - 1) + i); i--; } printf("The result is %d.\\n", sum); return 0;} ...

用c语言编程如何实现求和的程序代码?
一个存放和,一个从1开始到100,如下图所示。3、之后书写for循环,首先给i赋值为1,其中如果要求200以内和把数字100改为200即可。4、然后写for循环里面的内容,sum=sum+i;把每个i的值加到sum里面。5、最后进行输出,编写输出语句把它输出出来,sum为整形,故用%d,如下图所示就完成了。

用C语言编程实现1~100的累加求和。
include <stdio.h> include <stdlib.h> int main(){ int i,sum=0;for(i=1;i<=100;i++)sum+=i;printf("%d",sum);system("pause");}

这个题目能不能用C语言表示出来
因为我是学习计算机软件专业的,故可以很负责任地告诉你:首先你的这个题目肯定是能够通过 C 语言编程实现的,但是不会有人帮助你使用 C 语言具体实现你的需求。因为问题就在于:要想把自己头脑中的某一个具体想法通过具体的程序设计语言实现出来,那么毕竟还涉及到软件专业的其它课程的专业知识。例如:《...

求用C语言编程实现一个国际象棋 马怎么走的问题
C语言我不会,下面这个是易语言的,希望你能借鉴一下:熟悉国际象棋的人都知道,马在某个方格,可以在一步内到达的不同位置最多有8个。如图所示:4#3 5#0#2 6###1 7#8 (1)对马走的方法可以设定一个顺序,如当前位置在棋盘的(i,j)方格,下一个可能的位置依次为(i+2,j+1),(i+1,...

用c语言程序编程实现1-n之间的偶数和,n从键盘输入
include <stdio.h>void main(){ int sum=0,n,i; scanf("%d",&n); for(i=1;i<=n;i++) { if(i%2==0) sum+=i; } printf("%d",sum);}

C语言编程: 已知2015年是羊年,编程实现,输入任意年份,输出该年属相...
include<stdio.h>int main(){ int year; printf("请输入年份:"); scanf("%d",&year); year=(year-2015)%12; if(year<0) year+=12; switch(year) { case 0:printf("今年是羊年!\\n");break; case 1:printf("今年是猴年!\\n");break; case 2:print...

江西省19192324492: 如何在C++实现任意输入一个数学函数 -
富瞿心安: 定义一个自定义函数去实现所需要的功能和算法.

江西省19192324492: 用C++编程实现一个函数,输入任意面值人民币时,输入按面值100、50、20、10、5、2、1兑换的结果. -
富瞿心安: #include <stdlib.h> #include <iostream> // 在这里定义货币面值, 可任意修改和添加, 但是最后一个必须为1 int money[] = { 100, 50, 20, 10, 5, 2, 1 };int main() {int input;std::cout << "输入数值" << endl;std::cin >> input;for(int i = 0; input != 0 ...

江西省19192324492: c++ 编写一个函数统计任意一个字符串中字符、数字、其他字符出现的频率 -
富瞿心安: #include using namespace std; const int N=10;void main(){ char p[N]; cout<<"请输入"<<<...

江西省19192324492: “任意输入一个整数,将各位数字反转后输出”这个程序用C++程序怎么编? -
富瞿心安: #include<iostream> #include<string> using namespace std;int main(){string str;while(cin>>str){int length=str.size();for(int i=length-1;i>=0;i--){cout<<str[i]<<" ";}cout<<endl;}return 0; }这个你可以输入很大的整数都行的 ,你自己运行试试 希望我的回答能够帮到你.

江西省19192324492: 用C++编写一个函数,实现将输入的字符串逆序输出,字符串的输入和输出在main函数种实现. -
富瞿心安: #include "stdio.h" #include "string.h" main() {char ch[100];int i;printf("请输入一个字符串:\n");gets(ch);for(i=strlen(ch)-1;i>=0;i--){putchar(ch[i]);}printf("\n"); }

江西省19192324492: C++ 可以输入一个函数 -
富瞿心安: 有些语言的解释器是用C/C++实现的,可以参考Python解释器的源代码.

江西省19192324492: c++怎么写一个函数把输入无论是什么类型都转换成二进制?? -
富瞿心安: //#include "stdafx.h"//vc++6.0加上这一行.#include using namespace std;// void allto2(void *p,int b){ unsigned char n; char f,*q; for(f=0,q=(char *)p+b-1;q>=p;q--) for(n=0x80;n;n>>=1){ if(f==0 && (*q&n)==0) continue;//消除了前导0,若不需,删除...

江西省19192324492: 用c++编写该函数 -
富瞿心安: #include int func1(int n = 2) { int total = 1; int i = 1; int sum = 0; for(i = 1; i{ total *= n; sum += total; } return sum; } int main() { std::cout std::cout}

江西省19192324492: 用c或c++编写函数,将任意一个整数转换成对应的字符串.比如,输入256,转换成字符串"256" -
富瞿心安: # include <stdio.h> void tr(int x) {int i,a=1; char *p; for(i=1;i<10;i++) {a=a*10; if(a>=x) break; } p[i]='\0'; while(i>=0) {i--; p[i]=x%10+48; x=x/10; } puts(p); } main() { int a; printf("please input a "); scanf("%d",&a); tr(a); getch(); } 凑合着用吧

江西省19192324492: c++编程:编写一个函数,用来计算从键盘上输入的整数的阶乘. -
富瞿心安: #include<iostream.h> #include<stdlib.h> int factorial(int a) {int i,s=1;for(i=1;i<=a;i++){s=s*i;}return s; }int main(void) {int n;cout<<"请输入一个整数:";cin>>n;cout<<n<<"的阶乘为:"<<factorial(n)<<endl;system("Pause");return 1; }

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 星空见康网