code[vs]-Ticket Discount-floating point processing-ladder Bronze

Source: Internet
Author: User

Title Description Description

Enter the original ticket price (3 to 4 positive integer, Unit: Yuan), and then enter the ticket discount rate (up to one digit after the decimal point). program calculates the actual price of the ticket after discount (unit: Yuan. The result of the calculation is to round the single digit to the 10-digit "element". The input is only a single row of two numbers (two spaces separated by a space), the first is an integer, the ticket price, the second integer or real number (as real, up to 1 digits after the decimal point) represents the discount rate.

Input Sample 1:

888 7

Output Example 1:

620

Input Sample 2:

1255 7

Output Example 2:

880

Enter a description Input Description

The input is only a single row of two numbers (two spaces separated by a space), the first is an integer, the ticket price, the second integer or real number (as real, up to 1 digits after the decimal point) represents the discount rate.

Output description Output Description

The output is only a single positive integer representing the discounted ticket price.

Sample input Sample Input

888 7

Sample output Sample Output

620

Data range and Tips Data Size & Hint

The original ticket price is greater than 100 less than 9999, the discount rate is greater than 1 less than 9.9.

Idea: This problem is a bit complicated, you can save the ticket price and discount rate with two float floats, then calculate the product divided by 100 (why divide by 100, because to keep to 10 bits, if divided by 10 is only reserved to the bit, and then the result is returned to 10), you can use: = (int) (x+0.5 ) > (int) x? (int) x+1: (int) x This code to implement rounding, int type Y, floating-point type X, returns the result after rounding

The code is as follows:

1#include <stdio.h>2 intMain ()3 {4     floatb;5     floatC;6     intans;7scanf"%f%f",&a,&b);8c=a*b/ -;9Ans= (int) (c+0.5) > (int(c^ (int) c+1:(int) C;Tenprintf"%d\n", ans*Ten); One     return 0; A}

code[vs]-Ticket Discount-floating point processing-ladder Bronze

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.