Tuesday 8 January 2013

Let Us C Chapter 1 Problem No:H-k


#include<iostream.h>
#include<conio.h>
#include<stdio.h>
void main()
{
int a;
printf("Enter the money\n");
scanf("%d", &a);
int b;
b=a%10;
printf("give the customer %d coins\n", b);              
int c;
    a=a-b;
c=a%100;
c=c/10;
if(c>=5)
{c=c-5; // c-5 is done because if c=70 then ten's notes is (c-5)
printf("%d notes of ten\ngive 1 note of fifty\n", c);
}
else
printf("Give %d notes of ten\n", c);

int d;

d=a/100;
printf("Give %d notes of hundred\n", d);
}

========================================================================
Second Method:
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
void main()
{
int a; // inputs the money
cin>>a;
int b;
b=a%10; // coins
if(b!=0)
cout<<"Give coins to customer: "<<b<<endl;
a/=10;b=a%10; // to set tens
cout<<"Give of ten's notes to customer: "<<b<<endl;
a=a/10;b=a%10;
cout<<"Give of hundred's notes to customer: "<<b<<endl;
a/=10;
cout<<"Give of thouasnds notes to customer: "<<a<<endl;
}

No comments:

Post a Comment

Comments please: