C Tutorial
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 = Cost Amount - Sold Amount Discount Rate = (Discount * 100/Cost Amount)
#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
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
C Tutorial
Privacy Policy | Copyright2020 - All Rights Reserved. | Contact us
| Report website issues in Github
| Facebook page
| Google+ page