/*
rita has a money pouch containing Rsx (for example 700). There are equal number of 25 paise coins,
50 paise coins and one rupee coins. Write a C program to find out how many of each are there .
*/
/**************************
* author: umang bhatt *
* bhatt.umang7@gmail.com *
**************************/
/*
what i ubderstood:
0.25 x + 0.50 x + 1 x = amt
so dividing everything by 0.25 we get
x + 2x + 4x = amt * 4
therefore 7x = 4 amt
*/
#include<stdio.h>
void main()
{
int amt =700 ;
int i;
printf("Enter amount: " );
scanf("%d",&amt);
for( i = 1 ; i <= amt * 4 ; i++)
{
if( (7*i) == (4*amt) )
{
printf("no of coins are: %d\n",i );
break;
}
else if( (7*i) > (4*amt) )
{
printf("no such combination of coins can exist\n" );
break;
}
}
// printf("\n%f\n", ( (0.25*i) + (0.50 * i ) + ( i) ));
}
Saturday, October 1, 2011
no of coin problem
number operation
/************************** * author: umang bhatt * * bhatt.umang7@gmail.com * **************************/ /* consider following number 45 * 45 = 2025; 20+25 = 45. Write a program to generate number between 32 and 99 the satisfies the abovce property. */ #include<stdio.h> #define true 0 #define false 1 int foo(int n) { int i = n * n; int j ; int return_val; j = i % 100; i = i / 100; if((i+j)==n) { return_val = true; } else { return_val = false; } return return_val; } void main() { int i ; for( i = 32 ; i <= 99 ; i++) { if(foo(i) == true ) { printf("%d ",i ); } } printf("\n"); }
Labels:
20+25 = 45,
45 * 45 = 2025,
C program,
umang bhatt
Subscribe to:
Posts (Atom)