/*Problem:- A grocery store is selling oranges with price of
1 orange = 9 cent while if its 1 dozen then one dollar.Now write a function
that prompts end user to enter number of oranges ,accepts input of an integer
value and outputs total price of oranges in dollar & cents both,you can have just one parameter in
function/s you declare */
#include
#define PRICE 9 //actual parameter
int doz(int no); //no is formal parameter
int cents(int no); //same no is formal parameter
int main(void)
{
int n ; //n = no here n is actual parameters which is # of oranges
printf("Enter number of oranges to buy :- ");
scanf("%d",&n);
printf("\nPrice of %d oranges is %d Dollar",n,doz(n));
printf(" and %d cents\n",cents(n));
return 0;
}
int doz(int no)
{
return (( no / 12) * 1);
}
int cents(int no)
{
return ((no % 12) * PRICE);
}
Note:- Problem is from book "C by discovery" - Foster & Foster
No comments:
Post a Comment