An e-commerce company plans to give their customers a discount for the New Years holiday. The discount will be calculated on the basis of the bill amount of the order placed. The discount amount is the product of the sum of all odd digits and the sum of all even digits of the customer’s total bill amount.
Write an algorithm to find the discount amount for the given total bill amount.
Sample Input
billamount = 2514795
Sample Output
Output = 34
#include <stdio.h>
#include <stdlib.h>
int main(){
int billAmount;
int sumEvenDigits = 0;
int sumOddDigits = 0;
int d;
int discountAmount;
printf("Enter bill amount: ");
scanf("%d",&billAmount);
while (billAmount != 0) {
d = billAmount % 10;
if (d % 2 == 0) {
sumEvenDigits += d;
} else {
sumOddDigits += d;
}
billAmount = billAmount / 10;
}
discountAmount = sumEvenDigits*sumOddDigits;
printf("Discount amount: %d\n",discountAmount);
getchar();
getchar();
return 0;
}
Comments
Leave a comment