C语言:以最少数额表示美金的题解

c语言程序设计:现代方法其中一题
Write a program that asks the user to enter a U.S. dollar amount and then shows how that amount the smallest number of $20,$10,$5,and $1 bills:

#include<stdio.h>

int main()
{
    
    
    int tmp,t;
    
    printf("Enter a dollar amount:");
    scanf("%d",&t);
     
    tmp=t/20;
    printf("$20 bills:%d\n",tmp);
     
    t=t-tmp*20;
    tmp=t/10;
    printf("$10 bills:%d\n",tmp);
     
    t=t-tmp*10;
    tmp=t/5;
    printf("$5  bills:%d\n",tmp);
    
    t=t-tmp*5;
    printf("$1  bills:%d\n",t);
   
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_50536062/article/details/108690847