An E-Commerce commerce company plans to give their customers a discount for the New Years holiday. The discount will be calculated based on the bill amount of the order placed. The discount amount is the product of the sum of all odd digits and the sum of even digits of the customer’s total bill amount. If no odd digit is present in the bill amount, then 0 will be consider for its corresponding sum.
Write an algorithm to find the discount amount for the given total bill amount.
#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
/*
An E-Commerce commerce company plans to give their customers a discount for the New Years holiday.
The discount will be calculated based on the bill amount of the order placed.
The discount amount is the product of the sum of all odd digits and the sum of even digits of the customer’s total bill amount.
If no odd digit is present in the bill amount, then 0 will be consider for its corresponding sum.
Write an algorithm to find the discount amount for the given total bill amount.
*/
int main()
{
int Bill,SumEven=0,SumOdd=0,n,r;
printf("\mn\tEnter Bill Amount: "); scanf("%d",Bill);
n = Bill;
while(n!=0)
{
r = n%10;
n = n/10;
if(r%2==0) SumEven = SumEven + r;
else SumOdd = SumOdd + r;
}
printf("\n\tSum of Even Digits = %d",SumEven);
printf("\n\tSum of Odd Digits = %d",SumOdd);
printf("\n\tFinal Discount = %d",SumEven*SumOdd);
return(0);
}
Comments
Leave a comment