Задание 1:
#include <iostream>
using namespace std;
int trunc1(double* a)
{
return ((int)*a);
}
int main() {
double a, b, sum;
double *pa = &a, *pb = &b;
cout << "a: ";
cin >> *pa;
cout << "b: ";
cin >> *pb;
sum = *pa + *pb;
cout << "summ: " << sum << endl;
cout << "(int)sum: " << trunc1(&sum);
return 0;
Задание 2:
int num_of_duplicate_items(int *a, int *b, int length)
int res = 0;
for (int i = 0; i < length; i++, a++)
for (int j = 0; j < length; j++)
if (*a == *b) res++;
b++;
b -= length;
return res;
int a[5], b[5];
cout << "Array a: ";
for (int i = 0; i < 5; i++)
cin >> a[i];
cout << "Array b: ";
cin >> b[i];
cout << "Number of duplicate items: " << num_of_duplicate_items(a,b,5);
Задание 1:
#include <iostream>
using namespace std;
int trunc1(double* a)
{
return ((int)*a);
}
int main() {
double a, b, sum;
double *pa = &a, *pb = &b;
cout << "a: ";
cin >> *pa;
cout << "b: ";
cin >> *pb;
sum = *pa + *pb;
cout << "summ: " << sum << endl;
cout << "(int)sum: " << trunc1(&sum);
return 0;
}
Задание 2:
#include <iostream>
using namespace std;
int num_of_duplicate_items(int *a, int *b, int length)
{
int res = 0;
for (int i = 0; i < length; i++, a++)
{
for (int j = 0; j < length; j++)
{
if (*a == *b) res++;
b++;
}
b -= length;
}
return res;
}
int main() {
int a[5], b[5];
cout << "Array a: ";
for (int i = 0; i < 5; i++)
cin >> a[i];
cout << "Array b: ";
for (int i = 0; i < 5; i++)
cin >> b[i];
cout << "Number of duplicate items: " << num_of_duplicate_items(a,b,5);
return 0;
}