Sunday, October 25, 2020

C program: If the purchase amount is greater than 2000 20% discount otherwise 5% discount

First Method:

#include <stdio.h>

int main() {

    float n;

    printf("Enter the purchase amount:");

    scanf("%f",&n);

    if(n>=2000)

    {

        printf("Net Pay=%.2f",n-(n*0.20));

    }

    else

    {

        printf("Net Pay=%.2f",n-(n*0.05));

    }

}

Second Method:

#include <stdio.h>

int main() {

    float n;

    printf("Enter the purchase amount:");

    scanf("%f",&n);

    if(n>=2000)

    {

        printf("Net Pay=%.2f",n*0.80);

    }

    else

    {

        printf("Net Pay=%.2f",n*0.95);

    }

}

No comments:

Post a Comment

How to Fight Overthinking or Negative Thoughts?

How to Combat Overthinking or Negative Thoughts? 1. Don’t Fight Your Thoughts Trying to suppress or control negative thoughts often backfire...