Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- int main()
- {
- double p=-1,V=-1,n=-1,R=8.314,T=-1;
- for(int i=0;i<3;i++)
- {
- char c[10];
- scanf("%s",c);
- if(c[0]=='p')
- scanf("%s%lf",c,&p);
- else if(c[0]=='V')
- {
- scanf("%s%lf",c,&V);
- if(V==0)
- {
- printf("error\n");
- return 0;
- }
- }
- else if(c[0]=='n')
- {
- scanf("%s%lf",c,&n);
- }
- else if(c[0]=='T')
- {
- scanf("%s%lf",c,&T);
- if(T==0)
- {
- printf("error\n");
- return 0;
- }
- }
- }
- if(V==-1)
- {
- if(p==0)
- {
- if(n==0)
- printf("undefined\n");
- else
- printf("error\n");
- return 0;
- }
- V=n*R*T/p;
- if(V==0)
- {
- printf("error\n");
- return 0;
- }
- printf("V = %lf\n",V);
- }
- else if(p==-1)
- {
- p=n*R*T/V;
- printf("p = %lf\n",p);
- }
- else if(n==-1)
- {
- n=p*V/R/T;
- printf("n = %lf\n",n);
- }
- else if(T==-1)
- {
- if(n==0)
- {
- if(p==0)
- printf("undefined\n");
- else
- printf("error\n");
- return 0;
- }
- T=p*V/n/R;
- if(T==0)
- {
- printf("error\n");
- return 0;
- }
- printf("T = %lf\n",T);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment