Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- #include <iomanip>
- #include <math.h>
- using namespace std;
- const int N=5;
- int fact(int n)
- {
- int p=1;
- while (n>1)
- {
- p*=n;
- n--;
- }
- return p;
- }
- void zero_7(int a[N][N])
- {
- for (int j=0; j<N; j++)
- {
- int k=0;
- for (int i=0; i<N; i++)
- {
- if (a[i][j]%7==0)
- {
- k++;
- }
- }
- if (k>0)
- {
- for (int i=0; i<N; i++)
- a[i][j]=0;
- }
- }
- }
- int main()
- {
- setlocale(0,"Rus");
- //задача 4
- int mass[N][N];
- cout<<"начальный массив: "<<endl;
- for (int i=0; i<N; i++)
- {
- for (int j=0; j<N; j++)
- {
- mass[i][j]=rand()%8;
- cout<<setw(3)<<mass[i][j];
- }
- cout<<endl;
- }
- zero_7(mass);
- cout<<"конечный массив: "<<endl;
- for (int i=0; i<N; i++)
- {
- for (int j=0; j<N; j++)
- {
- cout<<setw(3)<<mass[i][j];
- }
- cout<<endl;
- }
- //задача 3
- double sum=1;
- double x;
- cout<<"Введите x"<<endl;
- cin>>x;
- int n;
- cout<<"Сколько слагаемых должно быть в ряде"<<endl;
- cin>>n;
- cout<<sum;
- double pr=x;
- for (int i=2; i<=n; i++)
- {
- pr*=x;
- if (i%2==0)
- {
- cout<<" - "<<pr<<"/"<<fact(i);
- sum-=(pr/fact(i));
- }
- else
- {
- cout<<" + "<<pr<<"/"<<fact(i);
- sum+=(pr/fact(i));
- }
- }
- cout<<endl<<"sum="<<floor(sum*1000)/1000<<endl;
- //задача 5
- cout<<"Введите числа. После введения 0 ввод закончится"<<endl;
- int chislo, k=0;
- double summ=0;
- bool dat=0;
- while (dat!=1)
- {
- cin>>chislo;
- if (chislo % 2 == 1)
- {
- k++;
- summ+=chislo;
- }
- dat = (chislo == 0);
- }
- if (k == 0) cout<<"В последовательности нет нечетных чисел"<<endl;
- else cout<<"Среднее арифм нечетных: "<<summ/k;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement