C Tutorial

# C Program to compute the discount rate

## C Program to calculate the discount percentage

This c program is used to compute the discount rate or discount percentage based on user inputs cost and sold amount of any products.

## Discount Percentage Formula

```Discount =  Cost Amount - Sold Amount
Discount Rate = (Discount * 100/Cost Amount)
```

## C Program to find the discount percentage

```#include<stdio.h>

void main()
{
double cost, sold, discount, discount_per;
printf("Enter cost amount: ");
scanf("%lf", &cost);
printf("Enter sold amount: ");
scanf("%lf", &sold);

discount =  cost-sold;
discount_per = ((discount *100)/cost);
printf("Discount Percentage: %lf\n", discount_per);
}
```

Output:

```\$ cc discount-percentage.c
\$ ./a.out
Enter cost amount: 5000
Enter sold amount: 4000
Discount Percentage: 20.000000

\$ ./a.out
Enter cost amount: 4500
Enter sold amount: 3750
Discount Percentage: 16.666667

```

## C program to round decimal places of double value

This c program rounds up the decimal places of double value 'discount percentage' using %.2lf formatter.

```#include<stdio.h>

void main()
{
double cost, sold, discount, discount_per;
printf("Enter cost amount: ");
scanf("%lf", &cost);
printf("Enter sold amount: ");
scanf("%lf", &sold);

discount =  cost-sold;
discount_per = ((discount *100)/cost);
printf("Discount Percentage: %.2lf\n", discount_per);
}
```

Output:

```\$ cc discount-percentage.c
\$ ./a.out
Enter cost amount: 4500
Enter sold amount: 3750
Discount Percentage: 16.67

```