[Solved] Geeta prefers to buy specific items, a 10 percent discount is provided if she buy more than 1200 of them

Geeta prefers to buy specific items, a 10 percent discount is provided if she buy more than 1200 of them. Write a programme to determine the overall costs if the quantity and price per item are input.

Input Format:

The total number of test cases (Y) appears on the first line.

The subsequent Y lines include integers for quantity and price on each line.

Sample Input:

3
100 120
10 20
1200 20

Constraints:

1 ≤ Y ≤ 1200

1 ≤ Price ≤ 100000

1 ≤ Quantity ≤ 100000

Output Format:

In a separate line, output will be the total costs while purchasing the items.

Sample Output:

12000.000000
200.000000
21600.000000

Solution

C++

#include <bits/stdc++.h>
using namespace std;
int main() {
    int t;
    cin >> t;
    for (int i = 0; i < t; i++) {
        double a, b;
        cin >> a >> b;
        double c = a * b;
        if (a > 1000) {cout << fixed << setprecision(6) << c * 9 / 10 << endl;}
        //sauravhathi
        else cout << fixed << setprecision(6) << c << endl;}
    }

C

#include <stdio.h>

int main(void) {
    int t;
	scanf("%d",&t);
	while(t--){
	    int a,b;
	    float c;
	    scanf("%d%d",&a,&b);
	    c=a*b;
	    if(a>1000)
	        printf("%f\n",c-(c*0.1));

        //sauravhathi
	    else
	        printf("%f\n",c);
	}
	return 0;
}

Java

import java.util.*;
import java.lang.*;
import java.io.*;

class Sauravhathi
{
	public static void main (String[] args) throws java.lang.Exception
	{
		
		Scanner sc=new Scanner(System.in);
		int t=sc.nextInt();
		while(t-->0){
		    float q=sc.nextFloat();
		    float p=sc.nextFloat();
            //sauravhathi
		    if(q>1000) System.out.println(0.9*p*q);
		    else System.out.println(p*q);
		}
	}
}

Python

for _ in range(int(input())):
    a=list(map(int,input().split()))
    if a[0]>1000:
        print(a[0]*a[1] - (a[0]*a[1]*0.1))

    #sauravhathi
    else:
        print(a[0]*a[1])

Happy Learning – If you require any further information, feel free to contact me.

Share your love
Saurav Hathi

Saurav Hathi

I'm currently studying Bachelor of Computer Science at Lovely Professional University in Punjab.

📌 Nodejs and Android 😎
📌 Java

Articles: 444

Leave a Reply

Your email address will not be published. Required fields are marked *