C – While purchasing certain items, a discount of 10% is offered if the quantity purchased is more than 1000. If quantity and price per item are input through the keyboard, write a program to calculate the total expenses.

#include <stdio.h>
int main()
{
    float qty, rate, bill;
    printf("Enter the quantity and rate ");
    scanf("%f %f", &qty, &rate);
    bill = qty * rate;
    if (qty > 1000)
    {
        bill = bill * 0.9;
    }
    printf("The total expenses = Rs %f", bill);
}
  1. Input Prompt: printf("Enter the quantity and rate: "); prompts the user to enter the quantity and rate.
  2. Input Reading: scanf("%f %f", &qty, &rate); reads the input values for quantity and rate.
  3. Initial Bill Calculation: bill = qty * rate; calculates the initial bill.
  4. Discount Application: if (qty > 1000) { bill = bill * 0.9; } applies a 10% discount if the quantity is greater than 1000.
  5. Output: printf("The total expenses = Rs %f", bill); prints the total expenses with two decimal places.
Scroll to Top
logo
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.