for :
// 66.
for(unsigned i = 5; i--;)
cout << i << endl; //4 3 2 1 0 !!!
for(unsigned i = 5; --i;)
cout << i << endl; //4 3 2 1 !!!
int x, y;
for (y = 1; y < 10; ++y) x = y;
printf ("%d %d\n", x, y); //9 10
int x, y;
for (y = 1; (x = y) < 10; ++y); printf ("%d %d\n", x, y); //10 10
int x, y;
for (x = 0, y = 1000; y > 1; ++x, y /= 10)
printf ("%d %d\n", x, y); //0 1000
//1 100
//2 10
int x, y;
for (x = 0, y = 1000; y > 1; x++, y /= 10);
printf ("%d %d\n", x, y); //3 1
// 67.
#define _USE_MATH_DEFINES
#include <math.h>
int main()
{
int i;
for (i = 0; i < 10; i++)
printf ("%d\n", rand ());
_getch();
return 0;
}
// 68.
[k, m+k)
#define _USE_MATH_DEFINES
#include <math.h>
int main()
{
int i, k, m;
scanf ("%d%d", &k, &m);
for (i = 0; i < 10; i++)
printf ("%4d\n", k+rand() % m);
_getch();
return 0;
}
// 69.
(0.0, 1.0)
#define _USE_MATH_DEFINES
#include <math.h>
int main()
{
int i;
printf ("random numbers from 0.0 to 1.0:\n ");
for (i = 0; i < 5; i++)
printf ("%lf\n ", ( rand()+0.0 ) /RAND_MAX);
// +0.0
//
_getch();
return 0;
}
:
random numbers from 0.0 to 1.0:
0.001251
0.563585
0.193304
0.808741
0.585009
// 70.
,
// srand()
#define _USE_MATH_DEFINES
#include <math.h>
#include <time.h> // time()
int main()
{
int i;
srand(100); // 100!!!
printf ("random numbers \n");
for (i = 0; i < 5; i++)
printf ("%8d", rand ());
printf ("\nrandom numbers are the same \n");
srand (100); //
for (i = 0; i < 5; i++)
printf ("%8d", rand ());
printf ("\nrandom numbers are the others \n");
srand (time(0)); // , !!!
|
|
for (i = 0; i < 5; i++)
printf ("%8d", rand ());
printf ("\n");
_getch();
return 0;
}
( ):
random numbers
365 1216 5415 16704 24504
random numbers are the same
365 1216 5415 16704 24504
random numbers are the others
26545 26201 2521 21152 26986
// 71.
//_1
const int N =10;
int main ()
{
int summa=0;
for(int i=1; i <=N; i++)
summa += i;
cout << summa << endl;
_getch();
return 0;
}
// _2
const int N=10;
int main ()
{
int summa=0;
for(int i = 1; i <= N;)
summa += i++;
cout << summa << endl;
_getch();
return 0;
}
// _3
const int N=10;
int main ()
{
for(int i=1, summa = 0; i <=N; cout << summa << endl)
summa += i++;
// cout << summa << endl; error!! Undeclared summa
_getch();
return 0;
}
// 72.
1.1 1.2 + 1.3 N > 0 ( ). .
int main ()
{
int N = 10;
float sign = 1;
float val = 1.1f;
float sum = 0;
for(int i = 0; i < N; ++i)
{
sum += sign*val;
sign *= -1;
val += 0.1f;
}
cout << sum << endl;
_getch();
return 0;
}
// 73.
//
char s;
for (s ='0'; s <= '9'; s++)
cout << s << " " << static_cast <int> (s) << endl;
//
char s;
for (s ='A'; s <= 'Z'; s++)
cout << s << " " << static_cast <int> (s) << endl;
for (s ='a'; s <= 'z'; s++)
cout << s << " " << static_cast <int> (s) << endl;
n
// 74.
const int DELAY =400000000;
int main ()
{
long i;
int n;
cout << "sec=?\n";
cin >> n;
for (; n; n--)
for (i = 0; i < DELAY; i++);
cout << n << endl;
_getch();
return 0;
}
N
// 75.
int main ()
{
unsigned N;
cout << " \n input N:"; cin >> N;
for (unsigned i = 2; i <= N / 2; i++) // 頠
if (!(N % i)) cout << i << " "; // i N
cout << endl;
_getch();
return 0;
}
,
// 76.
int main()
{
int n;
cin >> n;
for (int i = 2; i <= n/2; i++)
if (n % i == 0)
{cout <<"ne prostoe" << endl; _getch();return 1;}
cout << "prostoe" << endl;
_getch();
return 0;
}