Thursday, September 13, 2018

CALCULATING GAIN PERCENTAGE

  • Problem 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
  • CODING ARENA
  • #include <stdio.h>
    int main()
    {
      int a,b,c;
      scanf("%d%d%d",&a,&b,&c);
      printf("The gain percentage is=%.2f",((c-a-b)*1.0/(a+b))*100);   

    return 0;
    }
  • Test Case 1

    Input (stdin)
    4700
    
    800
    
    5800
    
    
    Expected Output
    The gain percentage is=5.45
  • Test Case 2

    Input (stdin)
    5000
    
    700
    
    5800
    
    
    Expected Output
    The gain percentage is=1.75

1 comment:

  1. What if a depreciation rate is also given, for eg. if the scooter's value decreases 10% every year (d)?

    ReplyDelete