// 38.
:
#define PRINT(int) printf("int = %d\n", int)
int x = 1, y = 1, z = 1;
x += y += z; | y=y+z= 2; x =x+y=3 |
PRINT(x < y? y : x); | 3 < 2 à à x=3 |
PRINT(x < y? x++: y++); | 3 < 2 à à 2, y=3 |
PRINT(x); | 3 |
PRINT(y); | 3 |
PRINT(z += x < y? x++: y++); | (z+=(3<3à à3) à 1+3=4, y=4 |
PRINT(y); | 4 |
PRINT(z); | 4 |
x = 3; y = z = 4;
PRINT(z >= y >= x)? 1: 0); | ((4>=4) >=3) à (1>=3)à à0 |
PRINT((z >= y) && (y >= x)); | ((4>=4) && (4>=3)) à(1) |
-----------------------------------------------------------------------------------------
// 39.
:
#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
Bool b;
int i = 3;
int a [5] = {0, 1, 2, 3, 4}; // 5 int
// 0 4
if (i >= 0 && i < 5 && a[i] == 3){
cout << 1 << endl;
}
else {
cout << 2 << endl;
}
if (!(i >= 0 && i < 5)? false: (a[i] == 3)) {
cout << 1 << endl;
}
else {
cout << 2 << endl;
}
if ((i >= 0 && i < 5)? (a[i] == 3): false) {
cout << 1 << endl;
}
else {
cout << 2 << endl;
}
_getch();
return 0;
}
-----------------------------------------------------------------------------------------
// 40.
/* */
#include <stdio.h>
#include <conio.h>
int main()
{
Int x, y, z;
x = y = z = 1;
x += y += z; //y=2; x=3;
printf("%d\n", x < y? y: x); //x=3
printf("%d\n", x < y? x++: y++); // y=2
printf("%d\n", x); // x=3
printf("%d\n", y); // y=3
z += x < y? x++: y++;
printf("%d\n", z); // z=4;
printf("%d\n", y); // y=4
x = 3; y = z = 4;
printf("%d\n", (z >= y >= x)? 1: 0); //0
printf("%d\n", (z >= y)&& (y >= x)? 1: 0); //1
printf(" \n ");
_getch();
return 0;
}
-----------------------------------------------------------------------------------------
// 41.
//
#define _USE_MATH_DEFINES
#include <cmath>
#include <iostream>
|
|
#include <conio.h>
using namespace std;
int main()
{
Int i;
long l;
double x;
cout << "Input i, l, x \n"; // -5, -555, -5.89
cin >> i >> l >> x;
cout << ' | ' << i << ' | ' << abs(i) << endl; //-5 5
cout << ' | ' << l << ' | ' << abs(l) << endl; //-555 555
cout << ' | ' << x << ' | ' << abs(x) << endl; //-5.89 5.89
_getch();
return 0;
}
-----------------------------------------------------------------------------------------
// 42.
//
#define _USE_MATH_DEFINES
#include <cmath>
#include <stdio.h>
#include <conio.h>
#ifndef M_PI
#define M_PI 3.14159265358979323846
#define M_PI_4 0.785398163397448309616
#endif
int main()
{
double x = M_PI/2,
y = cos(x);
printf("cos (%lf) = %lf\n",x, y);
printf("tan PI/4 =%lf\n", tan (M_PI_4));
//
printf("enter a real number between -1 and 1\n");
scanf_s("%lf",&x);
y = asin (x);
printf("asin (%lf) = %lf \n ", x, y);
_getch();
return 0;
}
-----------------------------------------------------------------------------------------
// 43.
// modf :
#define _USE_MATH_DEFINES
#include <math.h>
#include <stdio.h>
#include <conio.h>
int main()
{
double value = 1.2345,
int_part,
fraction_part;
fraction_part = modf (value, &int_part);
printf(" value:%lf int_part:%lf fraction_part:%lf \n ",
value, int_part, fraction_part);
_getch();
return 0;
}
:
value:1.234500 int_part:1.000000 fraction:0.234500
-----------------------------------------------------------------------------------------
// 44.
// fmod :
#define _USE_MATH_DEFINES
#include <math.h>
#include <stdio.h>
#include <conio.h>
int main()
{
double ab = 12.34, a;
a = fmod (ab, 10); // ab 10
printf("ab: %lf a: %lf \n ", ab, a);
_getch();
return 0;
}
:
ab: 12.340000 a: 2.340000
-----------------------------------------------------------------------------------------
// 45.
//
#define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
double x = 3.75,
y = -3.14;
cout << floor(x) << endl; // 3
cout << ceil(x) << endl; // 4
cout << floor(y) << endl; // -4
cout << ceil(y) << endl; // -3
_getch();
return 0;
}
-----------------------------------------------------------------------------------------
|
|
// 46.
:
int a = 5;
if (a!= 0) { /* 1*/
cout << "a!=0\n";
}
else {
cout << "a == 0\n";
}
if (a == 0) { /* 2*/
cout << "a == 0\n";
}
else {
cout << "a!= 0\n";
}
if (a) { / * 3, 1, */
cout << "a!= 0\n"; /* if */
}
else {
cout << "a == 0\n";
}
if (! a) { /* 4, 2, */
cout << "a == 0 \ n "; /* if*/
}
else {
cout << "a!= 0 \ n ";
}
-----------------------------------------------------------------------------------------
// 47.