C Program For Currency Denomination

Traditional Method:

The conventional approach employs a simple and uncomplicated technique for tallying currency denominations. An array is established to hold the different values of banknotes such as 500, 100, 50, and more. Users then input the total amount to be tallied. The software calculates the number of times each note can be accommodated within the specified amount by iterating through the array. Subsequent calculations involve processing the remaining amount.

Example:

Example

#include <stdio.h>

int main() {
    int notes[8] = {500, 100, 50, 20, 10, 5, 2, 1};
    int amount, temp;

printf("Enter the amount: ");
scanf("%d", &amount);

    temp = amount;

    for (int i = 0; i< 8; i++) {
printf("\n%d notes is: %d", notes[i], temp / notes[i]);
        temp = temp % notes[i];
    }

    return 0;
}

Output:

Output

Enter the amount: 3456
500 notes is: 6
100 notes is: 4
50 notes is: 1
20 notes is: 0
10 notes is: 0
5 notes is: 1
2 notes is: 0
1 notes is: 1

User-Defined Function Approach:

By utilizing this approach, we can encapsulate the functionality of counting notes within a custom function, enhancing the modularity of the code. This not only promotes good coding conventions but also helps maintain a succinct core codebase.

Example:

Example

#include <stdio.h>

void countNotes(int amount) {
    int notes[8] = {500, 100, 50, 20, 10, 5, 2, 1};
    int temp = amount;

    for (int i = 0; i< 8; i++) {
printf("\n%d notes is: %d", notes[i], temp / notes[i]);
        temp = temp % notes[i];
    }
}

int main() {
    int amount;

printf("Enter the amount: ");
scanf("%d", &amount);

countNotes(amount);

    return 0;
}

Output:

Output

Enter the amount: 56789
500 notes is: 113
100 notes is: 2
50 notes is: 1
20 notes is: 1
10 notes is: 1
5 notes is: 1
2 notes is: 2
1 notes is: 0

Pointer Approach:

This technique is a crucial aspect of C programming. The pointer technique can achieve the counting of notes in an alternative manner. The identical outcome can be reached by providing array locations and employing pointer calculations.

Example:

Example

#include <stdio.h>

void countNotes(int *notes, int *amount) {
    int temp = *amount;

    for (int i = 0; i< 8; i++) {
printf("\n%d notes is: %d", *(notes + i), temp / *(notes + i));
        temp = temp % *(notes + i);
    }
}

int main() {
    int notes[8] = {500, 100, 50, 20, 10, 5, 2, 1};
    int amount;

printf("Enter the amount: ");
scanf("%d", &amount);

countNotes(notes, &amount);

    return 0;
}

Output:

Output

Enter the amount: 1025
500 notes is: 2
100 notes is: 0
50 notes is: 0
20 notes is: 1
10 notes is: 0
5 notes is: 1
2 notes is: 0
1 notes is: 0

Conclusion:

In summary, streamlining the task of tallying currency notes in a specified sum proves to be a valuable competency employed across different sectors, spanning from retail to banking. The techniques outlined in this piece to achieve this objective consist of the conventional approach, the custom function approach, and the pointer approach, highlighting the versatility of C programming.

The traditional method offers transparency into the fundamental logic and ease of understanding. Using user-defined functions enhances the code's modularity and structure, facilitating easier management and upkeep. Conversely, the pointer method showcases the advanced capabilities of pointers in efficiently accessing array elements and manipulating data.

The primary objective is to accurately tally paper currency and streamline financial computations, irrespective of the method employed. These approaches minimize inaccuracies, enhance efficiency, and serve as a foundation for further exploration into the capabilities of C programming. The ability to mechanize these tasks is increasingly crucial with technological advancements, and mastering these methods equips programmers with valuable skills applicable in various sectors.

Input Required

This code uses input(). Please provide values below: