Programming with Passion

Make the best out of everything.

Sunday, 11 January 2015

Program

So this is my first Program in this blog it might be hard it might be easy. I don't know but for me it was easy. Yeah i find minor difficulty in making this up. But i build this up in few minutes.

Have you ever heard about the riddle which is like how many toffees we can get if on returning Y amount of rappers we get one toffee. when we have X amount of toffee well this program counts them.

You have to tell the compiler how much toffees you have at initial and then tell the amount of rappers by which we get one.

#include<iostream.h>
void main()
{
int X,Y,c=0;
cin>>X>>Y;
c=X;
while(X){
if(X>=Y)
{
X-=Y;
++X;
++c;
}
else
X=0;
}
cout<<c;
}
/*Here X is amount of toffees we have
Y is amount of rappers by which we get one toffee.
and c tells the total we get.*/

No comments:

Post a Comment