Лекционные примеры
Пример 1.
#include <cstdlib>
#include <iostream>
using namespace std;
int main()
{
cout << "Hello, World!" << endl;
cout << "I love C++" << endl;
system("PAUSE");
return 0;
}
Пример 2.
#include <cstdlib>
#include <iostream>
using namespace std;
int main()
{
double a, b;
cout << "Input a: ";
cin >> a;
cout << "Input b: ";
cin >> b;
double c = b;
b = a
a = c
cout << "a equals " << a << endl;
cout << "b equals " << b << endl;
system("PAUSE");
return EXIT_SUCCESS;
}
Пример 3.
#include <cstdlib>
#include <iostream>
using namespace std;
int main()
{
int a = 13/5;
int b = 13%5;
int c = 13.0/5;
double d = 13/5;
double e = 13%5;
double f = 13.0/5;
double g = 13/5 + 2/5;
double h = 13.0/5 + 2.0/5;
int i = 13.0/5 + 1.9/5;
int j = 2.0/5;
cout << "int a = 13/5 = " << a << endl;
cout << "int b = 13%5 = " << b << endl;
cout << "int c = 13.0/5 = " << c << endl;
cout << "double d = 13/5 = " << d << endl;
cout << "double e = 13%5 = " << e << endl;
cout << "double f = 13.0/5 = " << f << endl;
cout << "double g = 13/5 + 2/5 = " << g << endl;
cout << "double h = 13.0/5 + 2.0/5 = " << h << endl;
cout << "int i = 13.0/5 + 1.9/5 = " << i << endl;
cout << "int j = 2.0/5 = " << j << endl;
system("PAUSE");
return EXIT_SUCCESS;
}