1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
/A program that uses the arrhenius equation to calculate and print A and E_a to the screen.
//The following libraries will be used.
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
using namespace std;
double Ea(int T1, int T2, double K1, double K2, double R)//Works out the value of Ea.
{
double Ea, T11, T22, T, K;
T11=(1/T1);
T22=(1/T2);
T=T11-T22;
printf("%lg = T\n",T);
K=log(K1)-log(K2);
printf("%lg = K\n",K);
printf("%lg = R\n",R);
Ea=-((R*(log(K1)-log(K2)))/((1/T1)-(1/T2)));
printf("\n%lg",Ea);
return (Ea);
}
int main()//The Main Function. Prints Introductory Messages and asks for the data which will be used in the functions.
{
int T1,T2;//Defines the integer variables that need to be inputted.
double K1,K2;//Defines the double variables that need to be inputted.
double R;//Definites the double variabe the boltzmann constant.
R=8.314;//Defines the value of R.
printf("A Program to work out A and Ea using the Arrhenius equation.\n");//Introductory Message.
printf("\nPlease enter the values of T1(Temperature 1) and its corresponding\nreaction rate constant k1.\n");//Asks for the user to input T1 and k1.
printf("T1=");
scanf("%d",&T1);//Obtains the value of T1
printf("k1=");
scanf("%lg",&K1);//Obtains the value of k1
printf("\nPlease enter the values of T2(Temperature 2) and its corresponding\nreaction rate constant k2.\n");//Asks for the user to input T2 and k2.
printf("T2=");
scanf("%d",&T2);//Obtains the value of T2
printf("k2=");
scanf("%lg",&K2);//Obtains the value of k2
printf("T1 is %d and K1 is %lg, T2 is %d and K2 is %lg\n",T1,K1,T2,K2);//Confirmation Message to check the inputted values.
Ea(T1,T2,K1,K2,R);//Runs the function Ea which calculates the value of Ea using the data from the int main() function.
return 0;
}
|