Tech Unleashed

Wohoo!! We're on YouTube

Thursday, 20 January 2022

C program for "If the total selling price of 15 items and the profit earned on them is input through the keyboard, write a program to find the cost price of 1 item."

Problem: C program for "If the total selling price of 15 items and the profit earned on them is input through the keyboard, write a program to find the cost price of 1 item."

Logic used : 
  • Subtract profit from selling price and divide by 15
  • Store the result in a variable
  • Print that variable
Demo :
cost price = ( selling price - profit ) / 15

C program :

// Program by Shyam kanth

#include<stdio.h>

int main(){
    int sp,profit;
    float cp;
    printf("Enter the selling price of all 15 items : ");
    scanf("%d",&sp);
    printf("Enter the profit earned on them : ");
    scanf("%d",&profit);
    cp=(sp-profit)/15;
    printf("The cost price of one item is %.2f.",cp);
    return 0;
}

Codes used : 
  • #include < stdio.h > : Header file for input-output
  • int : Integer data type
  • sp, cp, profit : Variable used
  • printf : Function for displaying message
  • scanf : Function for taking input
  • %d : Format specifier for integer type data
  • %f : Format specifier for decimal data
Do comments, If any doubt
Know about me : Shyam Kanth

No comments:

Post a Comment