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

Finding Direction: Navigating Career Goals and Life Aspirations

  Finding Direction: Navigating Career Goals and Life Aspirations Life often presents us with a myriad of choices, and the path to fulfillme...