Answer to Question #250319 in C for Deepu

Question #250319
An e-commerce company plans to give their customers a special discount for the Christmas They are planning to offer a flat discount. The discount value is calculated as the sum of all the prime digits in the total bill amount.

A

Write an algorithm to find the discount value for the given total bill amount.
1
Expert's answer
2021-10-13T00:29:36-0400
#include <stdio.h>
int main()
{
    int x, y, amount, isPrime, sum=0;
    printf("Enter the total bill amount : ");
    scanf("%d", &amount);
    for(x=2; x<=amount; x++)
    {


        isPrime = 1;
        for(y=2; y<=x/2 ;y++)
        {
            if(x%y==0)
            {
                isPrime = 0;
                break;
            }
        }


        if(isPrime==1)
        {
            sum += x;
        }
    }


    printf("The discount value for the bill amount %d = %d", amount, sum);


    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