[ create a new paste ] login | about

Link: http://codepad.org/36ZsGNo4    [ raw code | output | fork ]

C++, pasted on Oct 7:
#include <iostream>
#include <ctime> 
#include <cmath>
 
using std::cout;
using std::cin;
using std::endl;
int sr_geo(int **arr, int n)
{
        int sr_geo=0; 
        float pr=1;
        for(int i=0; i<n; i++)
        {
                for(int j=0; j<n; j++)
                {
                        if(i==j)
                        {
                                pr*=abs(arr[i][j]);
                        }
                }
        }
        //cout<<"@"<<pr<<"@";
        sr_geo =(int)exp(log((float)pr)/n);
        return sr_geo; 
}
 
int main()
{    
         setlocale(LC_ALL,"Russian");
         srand((unsigned)time(NULL));
         int n;
         int sr;
         int **arr;
         //cout<<"Введите розмер массива: ";
         //cin>>n;
         n=4;
         arr = new int*[n];
         cout<<"Массив: "<<endl;
         for(int i=0; i<n; i++)
         {
                  arr[i] = new int[n];
                  for(int j=0; j<n; j++)
                   {
                     arr[i][j]=rand()%9+1;
                     cout<<arr[i][j]<<"  ";
                        }
            cout<<endl;
         }
         sr = sr_geo(arr,n);
         cout<<endl;
         cout<<"Сформированая матрица:"<<endl;
         for(int i=0; i<n; i++)
         {
                 for(int j=0; j<n; j++)
                 {
                         if((i+j)%2==0)
                         {
                                 arr[i][j]= sr;
                         }
                         cout<<arr[i][j]<<"  ";
                 }
                 cout<<endl;
         }
 
         delete arr;
         system("pause");
   return 0;
}


Output:
1
2
3
4
5
6
7
8
9
10
11
12
13
Массив: 
5  6  8  2  
8  2  3  6  
9  6  7  7  
2  7  1  6  

Сформированая матрица:
4  6  4  2  
8  4  3  4  
4  6  4  7  
2  4  1  4  

Disallowed system call: SYS_fork


Create a new paste based on this one


Comments: