Keep amounts in whole paise, add a list of prices, apply 18% GST with correct rounding, and print rupees.
Solution
main.c
#include <stdio.h>
void print_rupees(long long paise) {
const char *sign = paise < 0 ? "-" : "";
if (paise < 0)
paise = -paise;
printf("%sRs. %lld.%02lld\n", sign, paise / 100, paise % 100);
}
int main(void) {
long long prices[] = {19999, 4950, 125}; /* Rs. 199.99, 49.50, 1.25 */
long long total = 0;
for (int i = 0; i < 3; i++)
total += prices[i];
long long gst = (total * 18 + 50) / 100; /* 18%, rounded to the nearest paisa */
print_rupees(total);
print_rupees(gst);
print_rupees(total + gst);
print_rupees(-5);
return 0;
}
Output Verified by compiling and running
Rs. 250.74
Rs. 45.13
Rs. 295.87
-Rs. 0.05
All arithmetic is exact integer arithmetic. Adding 50 before dividing by 100 rounds the GST to the nearest paisa (25074 × 18 = 451332 → 4513.32 → 4513). Only printing splits rupees and paise.
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!
We use Google Analytics cookies to see how LearnFrenzy is used and make it better, and Google AdSense to keep it free.
No analytics or ad cookies are set until you accept. Privacy Policy
·
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!