Advertisement
Guest User

Untitled

a guest
Nov 21st, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.83 KB | None | 0 0
  1. // Program untuk volume dan tekanan dari suatu gas.
  2.  
  3. /*  Programmer  : William Handi Wijaya      Tanggal diselesaikan : 21 November 2019
  4.     NRP         : 05111940000087            Kelas                : Dasar Pemograman C */
  5.  
  6. #include <stdio.h>
  7. #define a 3.592  //konstanta a van der walls
  8. #define b 0.0427 //konstanta b van der walls
  9. #define R 0.08206 //konstanta R
  10.  
  11. void print_table(double, double);
  12. int main()
  13. {
  14.     //variable declaraations
  15.     double volume_initial, // input - volume awal
  16.            volume_final, // input - volume akhir
  17.            volume_increment, // input - pertambahan volume untuk tabel
  18.            kelvin_temp, // input - temperatur dalam kelvin
  19.            moles, // input - besar mol unsur (co2)
  20.            pressure; // tekanan
  21.     //program intro
  22.     printf("\nPlease enter at the prompts the number of moles of carbon dioxide, the absolute temperature, the initial volume in milliliters, the final volume, and the increment volume between lines of the table.");
  23.     //get values
  24.     printf("\nQuantity of carbon dioxide (moles)>");
  25.     scanf("%lf", &moles);
  26.     printf("\nTemperature (kelvin)>");
  27.     scanf("%lf", &kelvin_temp);
  28.     printf("\nInitial volume (milliliters)>");
  29.     scanf("%lf", &volume_initial);
  30.     printf("\nFinal volume (milliliters)>");
  31.     scanf("%lf", &volume_final);
  32.     printf("\nVolume increment (milliliters)>");
  33.     scanf("%lf", &volume_increment);
  34.     //displays the result
  35.     printf("\nVolume (ml) %5c Pressure (atm)",' ');
  36.    
  37.     //loop for each case
  38.     while(volume_initial <= volume_final)
  39.     {
  40.         pressure = ((moles*R *kelvin_temp) / (volume_initial/1000 - (b * moles))) - ((a * moles * moles) / volume_initial/1000 * volume_initial/1000);
  41.        
  42.         print_table(volume_initial, pressure);
  43.        
  44.         volume_initial += volume_increment;
  45.     }
  46.     printf("\n");
  47. }
  48.  
  49. //printing functions
  50. void print_table(double volume, double pressure)
  51. {
  52.     printf("\n%3c%.2f %10c %.4f",' ', volume, ' ', pressure);
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement