Advertisement
ahmfarisi

Untitled

Jul 19th, 2022
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.71 KB | None | 0 0
  1. #include<iostream>
  2. #include<cmath>
  3. using namespace std;
  4.  
  5. double hitungGradien(int y2, int y1, int x2, int x1){
  6.     return (double) (y2-y1) / (x2-x1);
  7. }
  8.  
  9. int main(){
  10.     int N;
  11.     int x[2500];
  12.     int y[2500];
  13.     int numberOfGradient;
  14.     double m[2500];
  15.     int count;
  16.    
  17.     cin>>N;
  18.     for(int i=0; i<N; i++){
  19.         cin>>x[i]>>y[i];
  20.     }
  21.    
  22.     cout<<endl;
  23.    
  24.     numberOfGradient = 0;
  25.     for(int i=0; i<N; i++){
  26.         for(int j=N-1; j>i; j--){
  27.             //cout<<x[i]<<","<<y[i]<<endl;
  28.             //cout<<x[j]<<","<<y[j]<<endl;
  29.             m[numberOfGradient] = abs(hitungGradien(y[j],y[i],x[j],x[i]));
  30.             numberOfGradient++;
  31.         }
  32.     }
  33.    
  34.     //cout<<numberOfGradient;
  35.    
  36.    
  37.     for(int k=0; k<numberOfGradient; k++){
  38.         cout<<k<<" = "<<m[k]<<endl;
  39.     }
  40.    
  41.     return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement