Senin, 06 Mei 2019

Program Penyelesaian Persamaan Linier dengan Metode Gauss Menggunakan C++

Disini saya akan membagikan Source Code Statis Metode Gauss untuk mencari nilai x, y, z, dan u yang telah ditentukan persamaannya dengan menggunakan bahasa pemrograman C++. Meskipun program yang saya buat ini belum sempurna setidaknya anda dapat memberikan saran dan masukan agar program saya menjadi lebih baik.

Berikut Source Codenya :

#include "stdio.h"

int main(){
    int b1k1 = 1;
    int b1k2 = -1;
    int b1k3 = -1;
    int b1k4 = 1;
    int b1k5 = 0;
    int b2k1 = 2;
    int b2k2 = 0;
    int b2k3 = 2;
    int b2k4 = 0;
    int b2k5 = 8;
    int b3k1 = 0;
    int b3k2 = -1;
    int b3k3 = -2;
    int b3k4 = 0;
    int b3k5 = -8;
    int b4k1 = 3;
    int b4k2 = -3;
    int b4k3 = -2;
    int b4k4 = 4;
    int b4k5 = 7;
   
  
    printf("\n [ %i | %i | %i | %i] [X] = [%i] \n", b1k1, b1k2, b1k3, b1k4, b1k5);
    printf(" [ %i | %i | %i | %i] [Y] = [%i] \n", b2k1, b2k2, b2k3, b2k4, b2k5);
    printf(" [ %i | %i | %i | %i] [Z] = [%i] \n", b3k1, b3k2, b3k3, b3k4, b3k5);
    printf(" [ %i | %i | %i | %i] [U] = [%i] \n\n", b4k1, b4k2, b4k3, b4k4, b4k5);
   
    printf(" B4 - 3.B1 \n");
    printf(" [ %i | %i | %i | %i | %i ] \n", b1k1, b1k2, b1k3, b1k4, b1k5);
    printf(" [ %i | %i | %i | %i | %i ] \n", b2k1, b2k2, b2k3, b2k4, b2k5);
    printf(" [ %i | %i | %i | %i | %i ] \n", b3k1, b3k2, b3k3, b3k4, b3k5);
    printf(" [ %i | %i | %i | %i | %i ] \n\n", b4k1, b4k2, b4k3, b4k4, b4k5);
  
    int b4k1b1 = b4k1 - (3*b1k1);
    int b4k2b1 = b4k2 - (3*b1k2);
    int b4k3b1 = b4k3 - (3*b1k3);
    int b4k4b1 = b4k4 - (3*b1k4);
  
    printf(" B2 - 2.B1 \n");
    printf(" [ %i | %i | %i | %i | %i ] \n", b1k1, b1k2, b1k3, b1k4, b1k5);
    printf(" [ %i | %i | %i | %i | %i ] \n", b2k1, b2k2, b2k3, b2k4, b2k5);
    printf(" [ %i | %i | %i | %i | %i ] \n", b3k1, b3k2, b3k3, b3k4, b3k5);
    printf(" [ %i | %i | %i | %i | %i ] \n\n", b4k1b1, b4k2b1, b4k3b1, b4k4b1, b4k5);
  
    int b2k1b1 = b2k1 - (2*b1k1);
    int b2k2b1 = b2k2 - (2*b1k2);
    int b2k3b1 = b2k3 - (2*b1k3);
    int b2k4b1 = b2k4 - (2*b1k4);
  
    printf(" B3 + 1/2.B2 \n");
    printf(" [ %i | %i | %i | %i | %i ] \n", b1k1, b1k2, b1k3, b1k4, b1k5);
    printf(" [ %i | %i | %i | %i | %i ] \n", b2k1b1, b2k2b1, b2k3b1, b2k4b1, b2k5);
    printf(" [ %i | %i | %i | %i | %i ] \n", b3k1, b3k2, b3k3, b3k4, b3k5);
    printf(" [ %i | %i | %i | %i | %i ] \n\n", b4k1b1, b4k2b1, b4k3b1, b4k4b1, b4k5);
  
    int b3k2b2 = b3k2 + (2/b2k2b1);
    int b3k3b2 = b3k3 + (b2k3b1/2);
    int b3k4b2 = b3k4 + (2/b2k4b1);
    int b3k5b2 = b3k5 + (b2k5/2);
  
    printf(" B4 + B2\n");
    printf(" [ %i | %i | %i | %i | %i ] \n", b1k1, b1k2, b1k3, b1k4, b1k5);
    printf(" [ %i | %i | %i | %i | %i ] \n", b2k1b1, b2k2b1, b2k3b1, b2k4b1, b2k5);
    printf(" [ %i | %i | %i | %i | %i ] \n", b3k1, b3k2b2, b3k3b2, b3k4b2, b3k5b2);
    printf(" [ %i | %i | %i | %i | %i ] \n\n", b4k1b1, b4k2b1, b4k3b1, b4k4b1, b4k5);
  
    int b4k4b2 = b4k4b1 + b3k4b2;
    int b4k5b2 = b4k5 + b3k5b2;
  
   
    printf(" [ %i | %i | %i | %i | %i ] \n", b1k1, b1k2, b1k3, b1k4, b1k5);
    printf(" [ %i | %i | %i | %i | %i ] \n", b2k1b1, b2k2b1, b2k3b1, b2k4b1, b2k5);
    printf(" [ %i | %i | %i | %i | %i ] \n", b3k1, b3k2b2, b3k3b2, b3k4b2, b3k5b2);
    printf(" [ %i | %i | %i | %i | %i ] \n\n", b4k1b1, b4k2b1, b4k3b1, b4k4b2, b4k5b2);
  
    printf("\n X - Y - Z + U = 0 ");
    printf("\n 2Y + 4Z - 2U = 8 ");
    printf("\n -U = -4 ");
    printf("\n Z = 3 \n");
   
    printf("\n--------------------------\n");
   
    int Z = 3;
    int U = -4/-1;
    int Z1 = 4*3;
    int U1 = 2*4;
    int ZU1 = Z1-U1;
    int ZUTot = 8-ZU1;
    int Y = ZUTot/2;
    int YZUTot = -Y-Z+U;
    int X = 0+(YZUTot)*-1;
  
    printf("\n Z = %i \n", Z);
   
    printf("\n -U = -4");
    printf("\n U = %i \n", U);
   
    printf("\n 2Y + 4Z - 2U = 8 ");
    printf("\n 2Y + %i - %i = 8 ", Z1, U1 );
    printf("\n 2Y + %i = 8 ", ZU1 );
    printf("\n 2Y = %i ", ZUTot );
    printf("\n Y = %i \n", Y );
   
    printf("\n X - Y - Z + U = 0 ");
    printf("\n X - %i - %i + %i = 0 ", Y, Z, U);
    printf("\n X %i = 0 ", YZUTot );
    printf("\n X = %i", X );
  
}


Langkah - langkah menjalankan program tersebut :
1. Langkah pertama kita akan menjalankan programnya dengan kilk compile & run atau klik F11

2. Kemudian akan muncul nilai x, y, z, dan u.


Sekian dan terima kasih :3


Share:

BTemplates.com

Diberdayakan oleh Blogger.