Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //CSC099 Individual Assignment
- //Name : MUHAMMAD IRFAN TIJANIE BIN MOHAMMAD TASNIM
- //STUDENT ID : 2019273078
- //GROUP : PI009E34
- #include <stdio.h>
- void realgas(float,int);
- void display(int,float);
- #define a 3.592 //co2 van der walls constant
- #define b 0.0427
- #define r 0.08206 //gas constant
- int main() //main fn
- {
- float mole;
- int temp;
- char choice;
- do {
- do{
- printf("Mole: ");
- scanf("%f", &mole);
- if(mole<=0) //reenter if mole<=0
- printf("Invalid Input . Please enter Positive value\n\n");
- }
- while(mole<=0);
- do{
- printf("Temperature (Kelvin): ");
- scanf("%d", &temp);
- if(temp<=0) //reenter if temperature<=0
- printf("Invalid Input . Please enter Positive value\n\n");
- }
- while(temp<=0);
- realgas(mole, temp);
- do{
- printf("\n\n\nDo you want to continue (Y,y-Yes, N,n-NO): ");
- scanf(" %c", &choice);
- if(choice!='Y'&&choice!='y'&&choice!='N'&&choice!='n') //reenter if invalid input
- printf("Invalid Input. Please enter Y,y or N,n\n");
- }
- while(choice!='Y'&&choice!='y'&&choice!='N'&&choice!='n');
- printf("-------------------------------------------------------------\n");
- }
- while(choice=='Y'||choice=='y');
- printf("From this calculation, you know that when volume (ml) in increasing,\npressure of gas reduce\n\nThank you");
- }
- void realgas(float mole, int temp) //calculation fn
- {
- int i_vol,f_vol,inc,dec;
- float ps;
- do{ //repeat if negative
- printf("Initial volume (milliliter): ");
- scanf("%d", &i_vol);
- if(i_vol<=0) //display error
- printf("Invalid Input . Please enter Positive value\n\n");
- }
- while(i_vol<=0);
- do{ //repeat if negative
- printf("Final volume(): ");
- scanf("%d", &f_vol);
- if(f_vol<=0) //display error
- printf("Invalid Input . Please enter Positive value\n\n");
- }
- while(f_vol<=0);
- if(i_vol<f_vol){ //user enter increment/decrement
- do{
- printf("Increment : ");
- scanf("%d", &inc);
- if(inc<=0) //reenter if increment<=0
- printf("Invalid Input . Please enter Positive value\n\n");
- }
- while(inc<=0);
- }
- else {
- do{
- printf("Decrement : ");
- scanf("%d", &dec);
- if(dec<=0) //reenter if decrement<=0
- printf("Invalid Input . Please enter Positive value\n\n");
- }
- while(dec<=0);
- }
- printf("\n\n%.4f moles of carbon dioxide at %d kelvin\n\n\n", mole, temp);
- printf("Volume (milliliter)\t Pressure(atm)\n");
- if(i_vol<f_vol)
- { do{
- ps=(mole*r*temp)/(i_vol*0.001-(mole*b))-((a*mole*mole)/(i_vol*0.001*i_vol*0.001));
- display(i_vol,ps); //fn call
- i_vol+=inc;
- }
- while(i_vol<=f_vol);
- }
- else
- {
- do{
- ps=(mole*r*temp)/(i_vol*0.001-(mole*b))-((a*mole*mole)/(i_vol*0.001*i_vol*0.001));
- display(i_vol,ps); //fn call
- i_vol-=dec;
- }
- while(f_vol<=i_vol);
- }
- }
- void display(int vol,float ps) //display fn
- {
- printf("%d\t\t\t %.4f\n", vol, ps); //show in tab
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement