2.1. , 45 109 .
#include <iostream>
#include <stdlib.h>
#include <conio.h>
#include <time.h>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
int high,mid,low,k=1,year,found;
char ch;
setlocale (NULL, ".1251");
//
srand((unsigned)time(NULL));
// rand()
// 0 RAND_MAX (RAND_MAX=32767),
//
do
{
found = 0;
low = rand()%10 + 45; cout << "min="<<low<<endl;
high = rand()%30 + 80;cout << "max="<<high<<endl;
cout<<", , "<<endl;
cout<<"( "<<low<<" "<<high<<") (y/n)"<<endl;
k=1; ch=_getch(); if(ch!= 'y' && ch!= 'Y')break;
// (
// )
while (low<=high &&!found)
{
mid = (low+high)/2;
cout<<" "<<mid<<" (y/n)?";
cin>>ch;
if (ch == 'y' || ch == 'Y')
{
cout<<"\n ! "<<k<<" ";
found = 1;
}
else
{
m2: cout<<"(>) (<)? ";
cin>>ch;
if (ch == '>')
low = mid+1;
else if (ch=='<')
high=mid-1;
else
{
cout<<" Shift+(< >)"<<'\n';
goto m2;
}
k++;
}
}
cout<<"\n\n (y/n)? ";
ch=_getch();
}
while(ch=='y' || ch=='Y');
return 0;
}
2.2. a b (a < b). , T ? ( !).
. a=3, b=5, T>7.
#include "stdafx.h"
#include <iostream>
#include <conio.h>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
int t3,t5,T; int a=3, b=5;
setlocale (NULL, ".1251");
printf(" ?"); cin>>T;
t3=0;
while(t3<=T/a)
{
t5=(T-a*t3)/b;
if(a*t3+b*t5 == T)
{cout<<a<<"-: "<<t3<<endl;
cout<<b<<"-: "<<t5<<endl;
break;
}
else
t3++;
}
if(t3>T/a)
cout<<" ";
_getch(); return 0;
}
2.3. , 1 . , 24 ., , , : 50, 25, 1.
|
|
#include <stdio.h>
#include <conio.h>
#include <iostream>
using namespace std;
int main()
{ int t, s;
setlocale (NULL, ".1251");
while(1)
{
printf(" ?");
scanf("%d",&s);
if(s >= 0 && s <= 100) break;
}
t = 100-s;
printf(" :");
while (t>=50)
{ t-=50; printf(" 50 "); }
while (t>=25)
{ t-=25; printf(" 25 "); }
while (t>=10)
{ t-=10; printf(" 10 "); }
while (t>=5)
{ t-=5; printf(" 5 "); }
while (t>=2)
{ t-=2; printf(" 2 "); }
while (t>=1)
{ t-=1; printf(" 1 "); }
getch(); return 0;
}
2.4. . , = 5784, : 5784=1*2*2*2*3*241
#include <stdio.h>
#include <conio.h>
#include <iostream>
using namespace std;
int main()
{
int i,M;
setlocale (NULL, ".1251");
printf(" ");
scanf("%d",&M);
printf("%d =1",M);
for(; M%2==0; M/=2)
printf("*2");
for(i=3; i <= M;)
if(M%i == 0)
{ printf("*%d",i); M/=i; }
else
i+=2;
getch(); return 0;
}
2.5. , ª ( 05). 40- .
ª
ªªª
ªªªªª
ªªªªªªª
ªªªªªªªªª
ªªªªªªªªªªª
#include "stdafx.h"
#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
int k, h, x, y;
setlocale (NULL, ".1251");
cout<<" ==> ";
cin>>h;
for(y=1; y<=h; y++)
{
for (x=0; x <= 40 - y; x++)
cout<<" ";
for (k=1; k<=2*y-1; k++)
cout<<'\05';
cout<<endl;
}
_getch(); return 0;
}