Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- double atvalt(double x, char f)
- {
- switch(f)
- {
- case 'k': { x*=1000; break; }
- case 'm': { x=x/1000; break; }
- case 'M': { x*=1000000; break; }
- }
- return x;
- }
- double u_(double P, double I)
- {
- double U;
- U=P/I;
- return U;
- }
- double p_(double U, double I)
- {
- double P;
- P=U*I;
- return P;
- }
- double i_(double P, double U)
- {
- double I;
- I=P/U;
- return I;
- }
- int main(int argc,char* argv[])
- {
- FILE* f1;
- int n,t=0,problem=1;
- double P=0,U=0,I=0;
- char p,f,abada;
- f1=fopen(argv[1],"r");
- fscanf(f1,"%d",&n);
- fscanf(f1,"%c",&abada);
- fscanf(f1,"%c",&p);
- while(t<n)
- {
- if(p=='U' || p=='I' || p=='P' )
- {
- if((fscanf(f1,"%c",&f))=='=')
- {
- switch(p)
- {
- case 'U':{ fscanf(f1,"%lf",&U); fscanf(f1,"%c",&f); U=atvalt(U,f); break;}
- case 'P':{ fscanf(f1,"%lf",&P); fscanf(f1,"%c",&f); P=atvalt(P,f); break;}
- case 'I':{ fscanf(f1,"%lf",&I); fscanf(f1,"%c",&f); I=atvalt(I,f); break;}
- }
- }
- else p=f;
- }
- if(p=='\n')
- {
- printf("Problem #%d\n",problem); problem++;
- if(U==0){ U=u_(P,I); P=0;I=0; printf("U=%.2fV\n\n",U); U=0; t++; goto get; }
- if(P==0){ P=p_(U,I); U=0;I=0; printf("P=%.2fW\n\n",P); P=0; t++; goto get; }
- if(I==0){ I=i_(P,U); P=0;U=0; printf("I=%.2fA\n\n",I); I=0; t++; goto get; }
- }
- get: fscanf(f1,"%c",&p);
- }
- fclose(f1);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement