#include <iostream>
#include <cmath>
signed main()
{
setlocale(LC_ALL, "Rus");
int cnt, countBoys = 0, countGirls = 0, sumHeightBoys = 0, sumHeightGirls = 0;
std::cout << "Введите количество детей в классе: ";
std::cin >> cnt;
int* height = new int[cnt];
for (int i = 0; i < cnt; i++)
std::cout << "Рост ребёнка №" << i + 1 << ": ";
std::cin >> height[i];
if (height[i] < 0) {
countBoys++;
sumHeightBoys += height[i];
}
else {
countGirls++;
sumHeightGirls += height[i];
std::cout << "Средний рост мальчиков: " << abs(sumHeightBoys) / countBoys << std::endl;
std::cout << "Средний рост девочек: " << sumHeightGirls / countGirls << std::endl;
return 0;
Объяснение:
1)
#include <string>
using namespace std;
int func(string s){
int sum = 1;
int i = 0;
while (i < s.length()){
if ((s[i] - '0')!=2 && (s[i] - '0')!=9)
sum*=(s[i]-'0');
i++;
return sum;
int main() {
string s = "";
cin>>s;
cout << func(s) <<endl;
2)
void change(int *arr){
int c = arr[3];
arr[3] = arr[4];
arr[4] = c;
for (int i=0;i<10;++i){
cout << i+1<<" = "<<arr[i]<<endl;
int arr[10];
cout << "Input element №:"<<i+1<<endl;
cin >> arr[i];
change(arr);
#include <iostream>
#include <cmath>
signed main()
{
setlocale(LC_ALL, "Rus");
int cnt, countBoys = 0, countGirls = 0, sumHeightBoys = 0, sumHeightGirls = 0;
std::cout << "Введите количество детей в классе: ";
std::cin >> cnt;
int* height = new int[cnt];
for (int i = 0; i < cnt; i++)
{
std::cout << "Рост ребёнка №" << i + 1 << ": ";
std::cin >> height[i];
if (height[i] < 0) {
countBoys++;
sumHeightBoys += height[i];
}
else {
countGirls++;
sumHeightGirls += height[i];
}
}
std::cout << "Средний рост мальчиков: " << abs(sumHeightBoys) / countBoys << std::endl;
std::cout << "Средний рост девочек: " << sumHeightGirls / countGirls << std::endl;
return 0;
}
Объяснение:
1)
#include <iostream>
#include <string>
using namespace std;
int func(string s){
int sum = 1;
int i = 0;
while (i < s.length()){
if ((s[i] - '0')!=2 && (s[i] - '0')!=9)
{
sum*=(s[i]-'0');
}
i++;
}
return sum;
}
int main() {
string s = "";
cin>>s;
cout << func(s) <<endl;
return 0;
}
2)
#include <iostream>
using namespace std;
void change(int *arr){
int c = arr[3];
arr[3] = arr[4];
arr[4] = c;
for (int i=0;i<10;++i){
cout << i+1<<" = "<<arr[i]<<endl;
}
}
int main() {
int arr[10];
for (int i=0;i<10;++i){
cout << "Input element №:"<<i+1<<endl;
cin >> arr[i];
}
change(arr);
return 0;
}