 Hello friends, I am Sanjay Gupta. In this video I am going to demonstrate you how you can calculate profit or loss by reading cost price and selling price from the user. Before starting you can note my information. You can visit or subscribe my YouTube channel through the link youtube.com slash sanjaygupta underscore tech school. You can download my programming app that is TechMS which is available on Google Play. Now coming on to the topic. Here I am going to implement a code in C programming which will check whether the seller has made profit or loss by using cost price and selling price. So first of all I am including a header file stdio.h then inside main function first time declaring variables cp for cost price sp for selling price then printf slash and enter cost price and selling price. So this message will be displayed on console then with the help of scanf I am going to read these two cost price and selling prices from the user. So for that purpose two format specifiers %f %f are used and then m%cp m%sp. So cost price will be stored inside cp and selling price will be stored inside sp variable. Now I am going to compare sp with cp. So sp is representing selling price and cp is representing cost price. So if this condition is true that is sp is greater than cp then seller is making profit. So profit equals to %e and sp minus cp. So with this printf statement profit equals to will be displayed and this %f sorry %f will be replaced by the difference between sp minus cp. So selling price is greater that's why seller is making profit. So profit amount will be displayed with the help of this printf statement. Now else if cp is greater than sp so in this case cost price is greater than selling price. So here seller will make loss so cp minus sp. So with this printf loss will be displayed on console and it will also display the amount of loss then again else and inside this else with the help of printf I am going to display no loss no profit. This means both prices are same and at last return 0. So this is the complete code which is implemented in c programming it is checking cost price and selling price and printing whether the seller has made profit or loss. Now I am executing this code I am entering cost price 100 and selling price 200 you can see it is showing profit equals to 100 which is correct. Now again I am executing this code this time cost price is 200 and selling this is 100 you can see it is showing loss equals to 100 again I am executing this code this time I am entering equal prices that is cost price is 100 and selling price is also 100 you can see the output is no loss no profit. So this way all three cases are working properly I hope you have understood how we can calculate profit and loss with the help of if else statement in c programming if you have any doubt you can contact me by following these details you can watch my various programming related videos and tutorials by this youtube channel that is youtube.com slash sanjay gupta underscore tech school you can use this URL for watching my programming related videos thank you for watching this video.