人民币有1元,5元,10元,20元,50元,100元的面值,写出一段C语言程序,找出和为143的人民币

高手们在线求帮请讲解下,人民币有1元,5元,10元,20元,50元,100元的面值,写出一段C语言程序,找出和为143的人民币
最新回答
枕花眠

2024-10-01 16:25:42

#include <stdio.h>

#include <stdlib.h>

int main()

{

 int ct1,ct5,ct10,ct50,ct20,ct100;

    int ctplan=1;

    for(ct100=0;ct100<=1;ct100++)

    {

  for(ct50=0;ct50<=2;ct50++)

        {

   for(ct20=0;ct20<=7;ct20++)

            {

    for(ct10=0;ct10<=14;ct10++)

                {

     for(ct5=0;ct5<=28;ct5++)

                    {

      for(ct1=0;ct1<=143;ct1++)

                        {

       if((ct100*100+ct50*50+ct20*20+ct10*10+ct5*5+ct1==143))

                            {

        printf("方案%d:\n",ctplan++);

                                if(ct100)

                                {  

         printf(" 100元:%d 张\t",ct100);

                                }

                                if(ct50)

                                {

         printf(" 50元:%d 张\t",ct50);

                                }

                                if(ct20)

                                {

         printf(" 20元:%d 张\t",ct20);

                                }

                                if(ct10)

                                {

         printf(" 10元:%d 张\t",ct10);

                                }

                                if(ct5)

                                {

         printf(" 5元:%d 张\t",ct5);

                                }

                                if(ct1)

                                {

         printf(" 1元:%d 张\t",ct1);

                                }

                                printf("\n");

                            }

                        }

                    }

                }

            }

        }

    }

 system("pause");

 return 0;

}

 

追答
如果程序编译错误试试去掉倒数第三行system函数
软耳兔兔

2024-10-01 02:40:46

因为题目中说要用最少的张数来表示,那就意味着要多100元的,低于100但大于50的用50元的,以此类推;
#include
void main()
{int a,i,j,k,n,m,s;//i表示100元的纸张数,j表示50元的纸张数,k表示20元的纸张数,n表示10元的纸张数,m表示5元的纸张数,s表示总的张数;
printf("请输入一个数:");
scanf("%d",&a); //把输入的那个数赋给a;
32785%100=i;
85%50=j;
35%20=k;
15%10=n;
5%5=m;
s=i+j+k+m+n;
printf("%d",s);
}