Procedures: 1. Using ssh login to your Pi or open a terminal on PiOS desktop 2. Create a new file for edit called Equ_Res.c 3. Either manually enter or copy and paste the following code into your editor window. Note: If you have copy & paste problems using vi, you may want to try the Linux editor called nano. Pasting into nano just requires that your position the cursor and then click middle button of mouse. You can also use gedit, or codeblocks IDE. Another option is editing a C file on your laptop with any editor, and then upload to your pi. #include <stdio.h> #include <stdlib.h> void get_resistors(int n,float #res): void calc_resistance(int n, float "res, float r_e); int main(void) { float resistors, R_equ; int nres; char ; char s_name[40]: while (1) { printf("How many resistors in parallel >>"); scanf("%d",&nres); resistors = (float *) malloc(nres sizeof(float)); if (resistors == NULL) puts("Cannot allocate enough memory"); else { get_resistors(nres, resistors): calc_resistance(nres, resistors,&R_equ); printf("Your last name?\n"); scanf("%s",s_name); printf("%s: Equivalent resistance is %8.31 ohmin".s_name, R_equ); printf("\nContinue?"); scanf("%s",&q); if (n == 'n')
if (q == 'n') break; } return(0); } void get_resistors(int n,float #res) { inti: for (i=1;i<=n;i++) { printf("Enter resistor %d >>",1); scanf("%f",res); res++; } } void calc_resistance(int n,float *res,float *r_e) { float r=0; int i; for (i=0;i<n;i++) { r+=1/("res); } *r_e=1/0 } res++; 5. Save your file and exit your editor 6. To verify your saved file, at the prompt, enter cat Equ_Res.c 7. Now, compile your C program by entering the following gcc Equ_Res.c-o Equ_Res 8. At the prompt enter the command line is - 9. Take a screenshot of your shell (window) showing the two files (Equ_Res.c and Equ_Res): 10. Run your program by entering JEqu_Res
10. Run your program by entering ./Equ_Res 11. Enter some value for the number of resistors in parallel, then enter each resistor's value. After you enter your last name, the shell prompt should show "Your last name: Equivalent resistance is x ohm." The actual value will be in the place of x. 12. Take a screenshot of your shell (window) showing your complete interaction with Equ_Res and enter it here: 13. Copy the file Equ_Res.c to a new file called Equ_Cap.c 14. Modify the source of Equ_Cap.c to prompt the user for parallel capacitor information that in turn computes the equivalent capacitance. Recall that the formula for equivalent parallel capacitance is not the same one used for equivalent parallel resistors. (If you don't know it google "capacitance in parallel formula"). Remember the unit of Capacitor is Farad. You program will print out "Equivalent capacitance is xxx Farad" 15. Compile Equ_Cap.c 16. Run and enter values in Equ_Cap 17. Take a screenshot of your shell (window) showing your complete interaction with Equ_Cap and enter it here: Shutdown your Pi
Procedures: 1. Using ssh login to your Pi or open a terminal on PiOS desktop 2. Create a new file for edit called Equ_Re
-
answerhappygod
- Site Admin
- Posts: 899604
- Joined: Mon Aug 02, 2021 8:13 am
Procedures: 1. Using ssh login to your Pi or open a terminal on PiOS desktop 2. Create a new file for edit called Equ_Re
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!