Microsoft Interview Question
Java ExperiencedsCountry: India
Interview Type: Phone Interview
#include <iostream>
void calculateNotes(int amount) {
int notes[] = {2000, 500, 200, 100};
int count[4] = {0};
for (int i = 0; i < 4; ++i) {
if (amount >= notes[i]) {
count[i] = amount / notes[i];
amount = amount - count[i] * notes[i];
}
}
// Display the output
for (int i = 0; i < 4; ++i) {
if (count[i] > 0) {
std::cout << notes[i] << "-" << count[i];
if (i < 3 && count[i + 1] > 0) {
std::cout << ",";
}
}
}
std::cout << std::endl;
}
int main() {
int inputAmount;
std::cout << "Enter the amount: ";
std::cin >> inputAmount;
calculateNotes(inputAmount);
return 0;
}
#include <iostream>
- Bhaskar Hemanth November 14, 2023void calculateNotes(int amount) {
int notes[] = {2000, 500, 200, 100};
int count[4] = {0};
for (int i = 0; i < 4; ++i) {
if (amount >= notes[i]) {
count[i] = amount / notes[i];
amount = amount - count[i] * notes[i];
}
}
// Display the output
for (int i = 0; i < 4; ++i) {
if (count[i] > 0) {
std::cout << notes[i] << "-" << count[i];
if (i < 3 && count[i + 1] > 0) {
std::cout << ",";
}
}
}
std::cout << std::endl;
}
int main() {
int inputAmount;
std::cout << "Enter the amount: ";
std::cin >> inputAmount;
calculateNotes(inputAmount);
return 0;
}