Tuesday 21 February 2017

Calculating Gain Percentage

QUESTION DESCRIPTION :

Vikram buys an old scooter for Rs. A and spends Rs. B on its repairs. If he sells the scooter for Rs. C , what is his gain %?
Write a C program to compute the gain %.
Input Format:
The first input is an integer which corresponds to A. The second input is an integer which corresponds to B. The third input is a float which corresponds to selling price



TEST CASE 1

INPUT

4700
800
5800

OUTPUT

The gain percentage is=5.45


EXPLANATION :

The code requires you to accept 3 integers from the user , which correspond to Cost Price , Repair Price and Selling Price respectively and then find the gain/profit percentage for the given input.

FORMULA :

Gain % = (( Selling Price - ( Cost Price + Repair Cost )) / (Cost Price + Repair Cost ) )*100


ALGORITHM : 

  • Accept 3 integers from the user ( a,b,c )
  • Calculate the gain % by using the given formula ( ((c-a-b)*1.0/(a+b))*100 ) ( Multiplying by 1.0 converts it to float ( can be used instead of type casting ) )
  • Print the result with the required message

SOLUTION : (Please use this as reference only)

CODE

No comments:

Post a Comment