یاس
12-01-2008, 12:10 PM
سكه 100 ريالي را به سكه هاي 2 و 5 و 10 و 20 و 50 ريالي خرد كند
#include<iostream.h>
#include<conio.h>
int main()
{
int i2,i5,i10,i20,i50,count=0;
unsigned long int sum;
clrscr();
for(i2=0;i2<=50;i2++)
for(i5=0;i5<=20;i5++)
for(i10=0;i10<=10;i10++)
for(i20=0;i20<=5;i20++)
for(i50=0;i50<=2;i50++)
{
sum=i2*2+i5*5+i10*10+i20*20+i50*50;
if(sum==100)
{
cout<<"\n 2 rials= "<<i2<< " 5 rials= "<<i5;
cout<<"\n 10 rials= "<< i10<< " 20 rials= "<<i20;
cout<<"\n 50 rials= "<< i50;
count++;
}
else
sum=0;
}
cout<<"\n number of correct times : "<<count;
getch();
return 0;
}
#include<iostream.h>
#include<conio.h>
int main()
{
int i2,i5,i10,i20,i50,count=0;
unsigned long int sum;
clrscr();
for(i2=0;i2<=50;i2++)
for(i5=0;i5<=20;i5++)
for(i10=0;i10<=10;i10++)
for(i20=0;i20<=5;i20++)
for(i50=0;i50<=2;i50++)
{
sum=i2*2+i5*5+i10*10+i20*20+i50*50;
if(sum==100)
{
cout<<"\n 2 rials= "<<i2<< " 5 rials= "<<i5;
cout<<"\n 10 rials= "<< i10<< " 20 rials= "<<i20;
cout<<"\n 50 rials= "<< i50;
count++;
}
else
sum=0;
}
cout<<"\n number of correct times : "<<count;
getch();
return 0;
}