Answer to Question #307435 in C for Jagga

Question #307435

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

1
Expert's answer
2022-03-07T10:26:58-0500






#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS