Advertisement
SenyaSych

Untitled

Mar 16th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.24 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <conio.h>
  3. #include <iomanip>
  4. #include <iostream>
  5. #include <stdio.h>
  6. #include <time.h>
  7. #include <string>
  8. #include <Windows.h>
  9. #include <math.h>
  10. #include <fstream>
  11.  
  12.  
  13. using namespace std;
  14.  
  15.  
  16. int main()
  17. {
  18.     srand(time(0));
  19.     setlocale( LC_ALL,"Russian" );
  20.  
  21.     ifstream fin;
  22.     ofstream fout;
  23.  
  24.  
  25.  
  26.     int n;
  27.     cout<<"\n\nВведите кол-во элементов массива n: ";
  28.     cin>>n;
  29.     float *A = new float[n];
  30.     float *B = new float[n];
  31.     cout<<"\nИскомый массив:\n";
  32.  
  33.     fout.open("in.txt");
  34.  
  35.     for (int i = 0; i < n; i++)
  36.     {
  37.         int temp = 0;
  38.         temp  = A[i] =  (float)(rand()%2100-1000)/100;;
  39.            fout << A[i]<< " ";
  40.     }
  41.  
  42.     fout.close();
  43.  
  44.     fin.open("in.txt");
  45.  
  46.  
  47.  
  48.     for (int i = 0; i < n; i++){
  49.         fin >> A[i];
  50.          cout<<A[i]<<"   ";
  51.     }
  52.  
  53.     int ind=0;
  54.     int k = -100;
  55.     for (int i=0; i<n; i++){
  56.             if (A[i]>k){
  57.                 k=A[i];
  58.                 ind = i;
  59.                 }
  60.     }
  61.     fin.close();
  62.     fout.open("out.txt");
  63.     fout<<"\nМаксим. элемент имеет индекс:"<<ind<<endl<<endl;
  64.     int kol=n/2;
  65.     for (int i=0,j=0; i<n; i++){
  66.  
  67.       if (i%2==0)
  68.         {
  69.        B[j]=A[i];
  70.        fout<<B[j]<<"   ";
  71.        j++;
  72.       }
  73.     kol =j;
  74.     }
  75.  
  76.      for (int i=0,j=kol; i<n; i++){
  77.  
  78.       if (i%2==1)
  79.         {
  80.        B[j]=A[i];
  81.        fout<<B[j]<<"   ";
  82.        j++;
  83.       }
  84.     }
  85.  
  86.  
  87.  
  88.         n=0;
  89.     do {
  90.         cout<<"\n\nВведите n: ";
  91.         cin>>n;
  92.     }while(n<20);
  93.     float *x = new float[n];
  94.     float *y = new float[n];
  95.     fout<<"\n\nИскомый массив x:\n";
  96.     for (int i = 0; i < n; i++){
  97.             x[i] =  (float)(rand()%2100-1000)/100;
  98.             fout<<x[i]<<"   ";}
  99.  
  100.    fout<<endl<<endl;
  101.         int kk=0;
  102.     for(int i=0; i<n;i++){
  103.         y[i] = tan(pow(2,x[i]));
  104.         if (y[i]<x[i])
  105.             kk++;
  106.         fout<<y[i]<<"   ";
  107.     }
  108.  
  109.     fout<<endl<<endl<<"Вычислить количество элементов массива у, меньших по своим значениям соответствующих элементов массива х.\n"<<kk;
  110.  
  111.     return 0;
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement