/* proba _1_1. cpp
*/
#include <stdio.h> // printf()
#include <conio.h> // _getch()
// main(): { }
int main()
{
printf("Ivanov Ivan \n ");
printf("Ok \ n ");
_getch(); // :
// ,
//
return 0;
}
:
Ivanov Ivan
Ok
-----------------------------------------------------------------------------------------
// 2.
/ * proba_ 2.cpp
system() */
#include <stdio.h>
#include <cstdlib> //
// system()
int main()
{
printf("Ivanov Ivan \n ");
printf("Ok \ n ");
system("pause"); // system()
//
return 0;
}
:
Ivanov Ivan
Ok
-----------------------------------------------------------------------------------------
// 3.
/ * proba_ 3.cpp
*/
#include <stdio.h>
#include <conio.h>
int main(){
//
// (16, 8, 10)
int i = 0 x abcd, j = 04567, k (1);
int ix = 1,
iy = 1,
iz = 1;
short shl = 4,
shm = 4;
unsigned long ulx (12345678);
//
printf("%x %o %d \ n ", i, j, k); // i,j,k (16,8,10)
printf("%d %d %d \n ", ix, iy, iz);
printf("%d %d \n ", shl, shm);
printf("%ld \n ", ulx);
_getch();
return 0;
}
:
abcd 4567 1
1 1 1
4 4
12345678
-----------------------------------------------------------------------------------------
// 4.
/ * proba_ 4.cpp
*/
#include <stdio.h>
#include <conio.h>
int main()
{ /* */
float x = 4.7; /* float x(4.7); warning */
/* ,
(4.7 f)*/
double y = 3.141592,
z = 0.6E-02;
Float fx(3.0f);
Double dy(3.141592);
printf("%f %lf %lf \n ", x, y, z);
|
|
printf("%f %lf \n ", fx, dy);
_getch();
return 0;
}
:
4.700000 3.141592 0.006000
3.000000 3.141592
-----------------------------------------------------------------------------------------
// 5.
/ * proba_ 5.cpp
*/
#include <stdio.h>
#include <conio.h>
int main() {
//
Bool ba (true);
Bool bc (1);
bool bp = false;
bool bb = bool (-25);
printf("%d %d \n ", ba, bc);
printf("%d %d \n ", bp, bb);
_getch();
return 0;
}
:
1 1
0 1
-----------------------------------------------------------------------------------------
// 6.
/ * proba_ 6.cpp
*/
#include <stdio.h>
#include <conio.h>
#define PI 3,14159265359
int main()
{
setlocale(LC_ALL, "RUS"); //
int number = 7;
float pies = 12.75;
int cost = 7800;
printf("%d %f . \n ", number, pies);
printf(" pi %f. \n ", PI);
printf(" : (%c%d). \n ", '$', 2 * cost);
_getch();
return 0;
}
-----------------------------------------------------------------------------------------
// 7.
/ * proba_ 7.cpp
*/
#include <stdio.h>
#include <conio.h>
int main()
{
int int1 = 45,
int2 = 15;
float f = 3.621f;
printf("int1 =%d | int1(3) =%3d | int1(-4) =%-4d | \n ", int1,int1,int1);
printf("int2 = %X | int2(3) = %3x | int2(4) = %4o | \n ", int2,int2,int2);
printf("f = %f | f = %4.2f | f = %6.1f | \n ", f, f, f);
f = 3123456.621f;
printf("f = %f | f = %4.2f | f = %6.1f | \n ", f, f, f);
_getch();
return 0;
}
:
int1 =45 | int1(3) = 45 | int1(-4) =45 |
int2 = F | int2(3) = f | int2(4) = 17 |
f= 3.621000 | f = 3.62 | f = 3.6 |
f= 3123456. 5 00000 [10] | f = 3123456. 5 0 | f = 3123456. 5 |
-----------------------------------------------------------------------------------------
// 8.
/ * proba_ 8.cpp
*/
#include <stdio.h>
#include <conio.h>
int main()
{
float f = 3.621f;
double db1 = 2.23;
char ch = 'z';
char *str = "aaaabbbbbcc";
printf("f=%g | f=%5g | f =%e | f =%+15E | \n ", f, f, f, f);
printf("db1=%5.2lf | db1 =%e | db1 =%4.1G | \n ", db1, db1, db1);
db1 = 212345.23123;
printf("db1=%5.2lf | db1 =%e | db1 =%4.1G | \n ", db1, db1, db1);
printf("ch=%c | ch =%03c | ch =%-03c | \n ", ch, ch, ch);
printf("str= %014s | \n str = %-014s | \n str = %s | \n ", str, str, str);
|
|
_getch();
return 0;
}
:
f=3.621 | f=3.621 | f =3.621000e+000 | f = +3.621000E+000 |
db1= 2.23 | db1 =2.230000e+000 | db1 = 2 |
db1=212345.23 | db1 =2.123452e+005 | db1 =2E+005 |
ch=z | ch =00z | ch =z |
str= 000aaaabbbbbcc |
str = aaaabbbbbcc |
str = aaaabbbbbcc |
-----------------------------------------------------------------------------------------
// 9.
printf() * ( , , , ). :
// float number = -12.3;int w = 10, // p = 4; // printf("%0 *. * f\n", w, p, number); // w = 15;p = 5; printf("%0 *. * f\n", w, p, number);
:
-0012.3000
-00000012.30000
!!! , .
-----------------------------------------------------------------------------------------
// 10.
y :
/ * proba_ 10.cpp
/ */
#include <stdio.h>
#include <conio.h>
int main()
{
Double x, y;
printf("x -?: \n ");
scanf_s("%lf", &x);
if (x < -2) y = 0;
else if (x >= -2 && x < 1) y = x;
else y = -x + 2;
printf("x = %lf, y = %lf \n ", x, y);
_getch();
return 0;
}
!!! : if()..... else if ().....
:
x?:
11.22
x = 11.220000, y = -9.220000
-----------------------------------------------------------------------------------------
// 11.
/ * proba_ 11.cpp
/ */
#include <stdio.h>
#include <conio.h>
int main()
{
Unsigned short x;
Bool b;
printf("x=? ");
scanf("%hu", &x);
b = bool(x);
printf("b = %d \n ", b);
// == 0, bool(x) false 0,
// != 0, bool(x) true 1,
_getch();
return 0;
}
:
x=? 2
b = 1
-----------------------------------------------------------------------------------------
++ [11]
// 12.
/* proba _12. cpp
++ std */
# include < iostream > // / ++
# include < conio. h > // _ getch ()
Int main()
{
std::cout << "Ivanov Ivan\n";
std::cout << "Ok" << std::endl;
_getch();
Return 0;
}
:
Ivanov Ivan
Ok
-----------------------------------------------------------------------------------------
// 13.
/ * proba_1 3.cpp
++ std */
#include <iostream>
#include <conio.h>
using namespace std; //!!!!
Int main()
{
cout << "Ivanov Ivan\n";
cout << "Ok" << endl;
_getch();
return 0;
}
:
Ivanov Ivan
Ok
-----------------------------------------------------------------------------------------
|
|
// 14.
/ * proba_1 4.cpp
++ std */
#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
cout << "Ivanov Ivan \n ";
cout << "Ok \n ";
_getch();
return 0;
}
:
Ivanov Ivan
Ok
-----------------------------------------------------------------------------------------
// 15.
<< .
/ * proba_1 5.cpp
++ */
#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
char ch1 (':'),
symbol ='d';
char c1 = 58; // :
/* !!!
, */
// ???
cout << c1 << " " << ch1 << endl; //::
cout << symbol << endl; // d
char first = '\n'; //esc-
char ch2 = '\''; //
cout << ch2 << endl; // '
char ch3 = 0x3f; // ? 16- /
char c3('?');
cout << ch3 << " " << c3<< endl; //??
//
cout << "\x 3f \? "; //??
cout << "\x 3f \n \? \n "; //? ?
_getch();
return 0;
}
-----------------------------------------------------------------------------------------
// 16.
/ * proba_1 6.cpp
++ */
#include <iostream>
#include <iomanip> // setw
#include <conio.h>
using namespace std;
int main()
{
cout << 1990 << setw(8) << 135 << endl
<< 1991 << setw(8) << 7290 << endl
<< 1992 << setw(8) << 11300 << endl
<< 1993 << setw(8) << 16200 << endl;
_getch();
return 0;
}
:
1990 135
1991 7290
1992 11300
1993 16200
-----------------------------------------------------------------------------------------
// 17.
(, ) dec, hex, oct. .
/ * proba_1 7.cpp
++ */
#include <iostream>
#include <iomanip> //
#include <conio.h>
using namespace std;
int main()
{
setlocale(LC_ALL, "RUS"); //
cout << ": " << oct << 10 << ' ' << 20 << endl;
cout << ": " << hex << 10 << ' ' << 20 << endl;
cout << ": " << dec << 10 << ' ' << 20 << endl;
|
|
_getch();
return 0;
}
:
: 12 24
: 14
: 10 20
-----------------------------------------------------------------------------------------
(0 , 0 ) showbase, uppercase, width(w) ios.
// 18.
/ * proba_1 8.cpp
++ */
#include <iostream>
#include <iomanip> //
#include <conio.h>
using namespace std;
int main()
{
long a = 1000,
b = 077;
double d = 0.12,
c = 1.3e-4;
cout.width (7); // = 7
// 16- /,
cout << hex << showbase << uppercase << a;
cout.width(7); // = 7
cout << b << endl; //
cout.width(12); // = 12
cout.setf (ios:: right); //
cout << d << endl;
cout.width(12); // = 12
cout.setf (ios:: right); //
cout << c << endl;
cout << d << endl;
cout << c << endl;
_getch();
return 0;
}
:
0X3E8 0X3F
0.12
0.00013
0.12
0.00013
-----------------------------------------------------------------------------------------
// 19.
/ * proba_1 9.cpp
++ */
#include <iostream>
#include <iomanip> //
#include <conio.h>
using namespace std;
int main()
{
Double x,
y;
cout << "enter a real number x:\n";
if (cin >> x) { //
y = x * x;
cout << "\nfor x=";
cout.width(9); // 9
cout << setiosflags(ios::fixed)<< setprecision(6) << x;
// . 6
cout << setw(8); // 8 " y="
cout << " y = ";
cout << setprecision(8); // 8 y
cout.width(15); // 15 y
cout << y << endl;
}
_getch();
return 0;
}
:
enter a real number x:
1.2345
for x=1.234500y=1.52399025
-----------------------------------------------------------------------------------------
++
// 20.
/ * proba_ 20.cpp
++ */
#include <iostream>
#include <conio.h>
#include <iomanip> //
using namespace std;
int main()
{
Double x, y;
cout << "vvedite x " << endl;
if (cin >> x) { // ???
if (x < -2) {y = 0;}
else if (x >= -2 && x < 1) {y = x;}
else {y = -x + 2;}
cout << setiosflags(ios::fixed) << setprecision(6);
cout << "x= " << x;
cout << " y= " << y << endl;
}
_getch();
return 0;
}
:
vvedite x
11.22
x= 11.220000, y= -9.220000
-----------------------------------------------------------------------------------------
// 21.
/ * proba_ 21.cpp
/ ++ */
#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
char str1[10],
str2[20],
str3[30];
cout << " Input string:\n"; //
// ???
cin >> str1 >> str2 >> str3; // odin dwa try
cout << "str1=" << str1 << " "
<< "str2=" << str2<< " "
<< "str3=" << str3 << endl;
|
|
_getch();
return 0;
}
:
Input string:
odin dwa try
str1= odin str2=dwa str3=try
-----------------------------------------------------------------------------------------
// 22.
/ * proba_ 22.cpp
( ) */
// do while
#include <iostream>
#include <conio.h>
using namespace std;
int main() {
Char ch;
cout << "Input char (end - x)\n";
do {
cout << ":"; //
cin >> ch; // <enter>
cout << ch << endl;
} while (ch!= 'x');
cout << " <x> - end " << endl;
_getch();
return 0;
}
:
Input char (end - x)
:q
:w
:e
:r
:t
:a
:s
:x
<x> - end
-----------------------------------------------------------------------------------------
// while
// 23.
#include <iostream>
#include <conio.h>
using namespace std;
int main() {
char ch;
cout << "Input char (end - x)\n";
while (cout << ":", cin >> ch, ch!= 'x')
{
cout << ch << endl;
}
cout << " <x> - end " << endl;
_getch();
return 0;
}