Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


pls help..

paper bills.. 1000, 500, 100, 50, 20, 10, 5, 1..

create a program that will count all the paper bills in
the number being input..

example:
enter a number: 3886

there is/are:

3 ->1000
1 ->500
3 ->100
1 ->50
1 ->20
1 ->10
1 ->5
1 ->1

example2:
enter a number: 728

there is/are:

0 ->1000
1 ->500
2 ->100
0 ->50
1 ->20
0 ->10
1 ->5
3 ->1

Answers were Sorted based on User's Feedback



pls help.. paper bills.. 1000, 500, 100, 50, 20, 10, 5, 1.. create a program that will count ..

Answer / etay

int _tmain(int argc, _TCHAR* argv[])
{
int num,i;
int bills[8] = { 1000, 500, 100, 50 ,20 ,10 ,5 ,1 };
int count[8] = {0};
printf("insert the number: \n");
scanf("%d",&num);
for (i=0; i<8;i++)
{
while (num >= bills[i])
{
num-=bills[i];
count[i]++;
}
}

for (i=0;i<8;i++)
{
printf("%d = %d \n",bills[i],count[i]);
}
scanf("%d",&num);

return 0;
}

Is This Answer Correct ?    6 Yes 1 No

pls help.. paper bills.. 1000, 500, 100, 50, 20, 10, 5, 1.. create a program that will count ..

Answer / aruna

The above program works gud. But I have small suggestion.

bill_count[i] = (val>=5?val/bill[i]:val);

This val >=5 will be executed every time though it is not
needed. Simpley we can give Quotient value in bill_count[i].
ie
bill_count[i] = val/bill[i];

Is This Answer Correct ?    3 Yes 0 No

pls help.. paper bills.. 1000, 500, 100, 50, 20, 10, 5, 1.. create a program that will count ..

Answer / subrata

#include<iostream>
using namespace std;



int main()
{
int bill[]={1000, 500, 100, 50, 20, 10, 5, 1};
int bill_count[]={0,0,0,0,0,0,0,0};

int size=8;
int val=728;


for(int i=0; i<size; i++)
{
if(val > bill[i] )
{

bill_count[i] = (val>=5?val/bill[i]:val);
val = val%bill[i];

}
}

for(int i=0; i<size; i++)
{
cout<< bill_count[i]<<" X " << bill[i]<<endl;
}

system("pause");
exit(0);
}

Is This Answer Correct ?    5 Yes 5 No

pls help.. paper bills.. 1000, 500, 100, 50, 20, 10, 5, 1.. create a program that will count ..

Answer / anand

nt main()
{
int number,count;
int currency[] = {1000, 500,100,50, 20, 10,5, 1};
cout<<"enter the number";
cin>>number;
for(int i=0; i<8;++i)
{
count = 0;
while(number >= currency[i])
{
number -= currency[i];
++count;
}
cout<<count<<"---"<<currency[i]<<"notes"<<endl;
}

getchar();
cout<<endl;

return 0;
}

Is This Answer Correct ?    4 Yes 4 No

Post New Answer

More C++ General Interview Questions

What causes a runtime error c++?

0 Answers  


What is the precedence when there is a global variable and a local variable in the program with the same name?

0 Answers  


Which one between if-else and switch is more efficient?

0 Answers  


What is insertion sorting?

0 Answers  


What is polymorphism in c++? Explain with an example?

0 Answers  


What is the Diffrence between a "assignment operator" and a "copy constructor"?

3 Answers   Wipro,


Which c++ compiler is best?

0 Answers  


What is double in c++?

0 Answers  


What is a conversion constructor?

1 Answers  


Explain register storage specifier.

0 Answers  


What is function overriding in c++?

0 Answers  


If you had the following code: int x = 23; int *y; y = &x; The instruction y++; does what?

2 Answers  


Categories