• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# Untitled

a guest Apr 23rd, 2019 98 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. #include<bits/stdc++.h>
2. using namespace std;
3. double a[20][20],d,det;
4. int n;
5. int prim(int a) {
6.     if(a < 2)
7.         return 0;
8.     for(int i = 2; i * i <= a; i++)
9.         if(a % i == 0)
10.             return 0;
11.     return 1;
12.     }
13.
14. int prime = 0;
15. int main(){
16.     ifstream cin("prob.in");
17.     ofstream cout ("prob.out");
18.     cin>>n;
19.     for(int i=1;i<=n;i++)
20.         for(int j=1;j<=n;j++)
21.             cin>>a[i][j];
22.     for(int i=1;i<=n;i++){
23.         for(int j=i+1;j<=n;j++)
24.             if(j!=i){
25.                 d=a[j][i]/a[i][i];
26.                 for(int k=1;k<=n;k++)
27.                     a[j][k]-=a[i][k]*d;
28.             }
29.     }
30.     cout<<endl<<"matricea zerografiata "<<endl;
31.     for(int i=1;i<=n;i++){
32.         for(int j=1;j<=n;j++)
33.             cout<<setprecision(2)<<fixed<<a[i][j]<<' ';
34.         cout<<endl;
35.     }det=1;
36.     for(int i=1;i<=n;i++){
37.         det*=a[i][i];
38.         if(prim(abs(a[i][i]))){
39.             prime++;
40.         }
41.         }
42.     cout<<"Determinantul ="<<det<<endl;
43.     if(prime > 1)cout << "avem "<<prime << " nr prime pe diagonala" <<endl;
44.     if(prime = 1)cout << "avem un numar prim pe diagonala"<<endl;
45.     if(!prime) cout << "nu sunt numere prime pe diagonala " <<endl;
46.     return 0;
47. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top