标题:硬币兑换问题如何显示所有方案
取消只看楼主
大神阿三
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2015-10-26
 问题点数:0 回复次数:0 
硬币兑换问题如何显示所有方案
当我输入10的时候方案有四千多种,但是显示的却不是全部,如何可以让其显示全部
#include<stdio.h>
#include<conio.h>
#include<windows.h>

int FangAnBuZou(int ,int ,int ,int ,float );
void goodbye(void);



void main(void)
{
    float n;
    int wufen,yijiao,wujiao,yiyuan;
    int count=0;
    int input=15;

    do
    {
        count=0;
        system("cls");
        printf("\n请输入金额\n");
        printf("\n范围是0-10元\n");
        scanf("%f",&n);
        if(n>=0&&n<=10)
        {
          for(wufen=0;wufen<=n*100/5;wufen++)
          {
           
            for(yijiao=0;yijiao<=n*10;yijiao++)
            {
               
                for(wujiao=0;wujiao<=n*10/5;wujiao++)
                {

                      for(yiyuan=0;yiyuan<=n;yiyuan++)
                    {
                    
                        if(FangAnBuZou(wufen,yijiao,wujiao,yiyuan,n)==1)
                        {
                            count++;
                             printf("%.2f元可以兑换成%d个五分硬币,%d个一角硬币,%d个五角硬币,%d个一元硬币\n",n,wufen,yijiao,wujiao,yiyuan);
                        }


                    }

                }

            }

          }

        printf("\n共有%d种方案\n",count);
        printf("\n按任意键继续,按esc键退出\n");
        }
        else
        {
        printf("\n输入范围有误,请重新输入\n");
        }
        input=getch();
    }while(input!=27);
    goodbye();
}

int FangAnBuZou (int wufen,int yijiao,int wujiao,int yiyuan,float n)
{
    if(wufen*0.05+yijiao*0.1+wujiao*0.5+yiyuan*1==n)
    {
       return 1;
    }
}

void goodbye(void)
{
    system("cls");
    printf("\n***************\n");
    printf("\n***欢迎使用****\n");
    printf("\n***************\n");
}
搜索更多相关主题的帖子: include system count 如何 
2015-11-01 21:14



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-458791-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.014573 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved