Write c program | Sololearn: Learn to code for FREE!


Write c program

Given a situation, you're going to stationary shop and buying five long size unruled classmate notebooks for writing notes for five different subjects. You paid Rs.500 to the shopkeeper for which the shopkeeper gave back Rs.25 back to you as change.  Write a C program to find the cost of each notebook that you've bought. Give 500 as input to the system using scanf statement.


10/21/2021 9:08:58 AM


6 Answers

New Answer


structure is the best concept to implement this requirement struct shop { char book[50]; int price; }; #include<stdio.h> void main() { struct shop s; printf(”Enter book name :”); scanf(”%s”, s.book); printf(”Enter available amount :); scanf(“%d”,&s.price); printf(”Amount in pocket : %d\n”, s.price); printf(”Book = %s\n”, s.book); s.price = s.price - 475; printf(”Available amount : %d\n”, s.price); }


Written. Now what's your doubt ?


You need to declare paid as input variable. int paid; scanf("%d",&paid);


Kindly share your attempt!!


Everything seems to be right in your code BHARGAV , What's your problem?!


#include <stdio.h> int main() { int paid=500,change=25,cost=0,singlebook=0; cost=paid-change; singlebook =cost/5; printf("%d",singlebook); return 0; }