From 8aeeb73764c2c3130610eceba57f8a63c2dd818a Mon Sep 17 00:00:00 2001 From: Chinmay Patil <96351859+Chin2024@users.noreply.github.com> Date: Sat, 22 Oct 2022 20:59:36 +0530 Subject: [PATCH] Create Denomination of coins.c MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit C Programming code to solve STACKS – DENOMINATIONS, N number of Coins are of denominations of 1, 2, 5, and 10. --- stack/Denomination of coins.c | 94 +++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 stack/Denomination of coins.c diff --git a/stack/Denomination of coins.c b/stack/Denomination of coins.c new file mode 100644 index 0000000..d4b5e2f --- /dev/null +++ b/stack/Denomination of coins.c @@ -0,0 +1,94 @@ +//CODE: + +#include +#include +#include +#include +#define SIZE 100 +struct stack +{ + int coin[SIZE]; + int top; +}; +void push(struct stack *sptr, int num); +void pop_count_display(struct stack *sptr); +int main() +{ + struct stack * sptr; + struct stack s; + sptr=&s; + sptr->top=-1; + int c,n,i; + scanf("%d",&n); + if(n<0) + { + printf("Invalid number of coins"); + exit(0); + } + for(i=0;itop==SIZE-1) + { + printf("Stack Overflow\n"); + } + else + { + sptr->top++; + sptr->coin[sptr->top]=num; + } +} +void pop_count_display(struct stack *sptr) +{ + int i,c1=0,c2=0,c5=0,c10=0,c=0; + for(i=sptr->top;i>=0;i--) + { + if(sptr->coin[i]==1) + { + c1++; + } + + else if(sptr->coin[i]==2) + { + c2++; + } + else if(sptr->coin[i]==5) + { + c5++; + } + else if(sptr->coin[i]==10) + { + c10++; + } + else + { + c++; + } + sptr->top--; + } + printf("Coins of 1 re = %d\n",c1); + printf("Coins of 2 rs = %d\n",c2); + printf("Coins of 5 rs = %d\n",c5); + printf("Coins of 10 rs = %d\n",c10); + printf("Coins of invalid denominations = %d",c); +} + + +/*OUTPUT: + +Input (stdin) +5 +1 2 5 10 1 + +Your Output (stdout) +Coins of 1 re = 2 +Coins of 2 rs = 1 +Coins of 5 rs = 1 +Coins of 10 rs = 1 +Coins of invalid denominations = 0 */