Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- `#include <stdio.h>
- #include <ctype.h>
- #include <stdlib.h>
- #include "prog8_functions.h"
- int main() {
- FILE* Volt = NULL;
- FILE* Resist = NULL;
- FILE* fp_output;
- char file1 [200]; //file of resistors
- char file2 [200]; //file of Voltages
- char fileout [200];
- int M;
- int p = 0;
- double a;
- double b;
- double I;
- double P;
- double c = 10000;
- double d = 10000;
- double e = 10000;
- double f = 0;
- double g = 0;
- double h = 0;
- double i = 0;
- double j = 0;
- double k = 0;
- do{
- printf("Enter name of file for resistor input:");
- scanf("%s", file1);
- if( Resist == NULL ){
- printf("Invalid file name\n");
- }
- else{
- M = M + 1;
- }
- }while (M != 1);
- do{
- printf("Enter name of file for voltage input:");
- scanf("%s", file2);
- if( Volt == NULL ) {
- printf("Invalid file name\n");
- }
- else{
- M = M + 1;
- }
- }while (M != 2);
- printf("Enter name of file for output:");
- scanf("%s", fileout);
- Volt = fopen(file1, "rb");
- Resist = fopen(file2, "rb");
- fp_output = fopen(fileout, "w");
- fprintf(" R (ohms) V (volts)\n");
- do{
- fread(&a, sizeof(a), 1, Volt);
- fread(&b, sizeof(b), 1, Resist);
- fprintf("RV pair %d: %.2lf %.2lf\n", p, a, b);
- p = p + 1;
- if(b < c ){
- c = b;
- }
- if(b > f ){
- f = b;
- }
- I = b / a;
- P = I * b;
- if(I < d ){
- c = b;
- }
- if(I > g ){
- f = b;
- }
- if(P < e ){
- c = b;
- }
- if(P > h ){
- f = b;
- }
- i = i + b;
- j = j + I;
- k = k + P;
- }while((fscanf(Volt, "%.2lf", &a) != EOF) && (fscanf(Resist, "%.2lf", &b) != EOF));
- i = i / (p + 1);
- j = j / (p + 1);
- k = k / (p + 1);
- fprintf(" Voltage Current Power\n");
- fprintf("MIN %.2lf %.4lf %.4lf\n", c, d, e);
- fprintf("MAX %.2lf %.4lf %.4lf\n", f, g, h);
- fprintf("AVG %.2lf %.4lf %.4lf\n", i, j, k);
- //fwrite(userNums, sizeof(int), NUM_VALUES, outFile);
- fclose(Volt);
- fclose(Resist);
- fclose(fp_output);
- return 0;
- }`
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement