Question

In: Computer Science

Write a C program that does the following In this part, you will write more complicated...

Write a C program that does the following

In this part, you will write more complicated functions. They will require parameters and return values. The purpose is to give you experience with these components, and to show you how functions can be used to break your code down into smaller parts. You will also get some more experience with iterating through arrays.Open repl project Lab: User-Defined Functions 2. Write a program that does the following:

1.(20 pts.) Allows the user to enter a sequence of up to 100 resistance values. The method of obtaining the input is up to you, but ​the values must be stored in an array​.

2.(20 pts.) Calculates the equivalent series resistance of the resistance values. This calculation must be done in a user-defined function that accepts the array of resistance values and the number of values in the array as parameters, and returns the equivalent series resistance.

3.(20 pts.) Calculates the equivalent parallel resistance of the resistance values. This calculation must be done in a user-defined function that accepts the array of resistance values and the number of values in the array as parameters, and returns the equivalent parallel resistance.

4.(20 pts.) Calls these two functions from the main function, and prints their return values(the equivalent series and parallel resistances).

Solutions

Expert Solution

Program:

#include<stdio.h>

float findSeries(float a[], int n);
float findParallel(float a[], int n);

int main()
{
float a[100];
int i=1,n;
float res=0, R=0, parallel = 0;
  
printf("Enter the number of Resistance: ");
scanf("%d",&n);
  
while(i <= n) {
printf("Enter the value for %d resistor: ",i);
scanf("%f",&a[i]);
i++;
}
  
printf("Equivalent Series Resistance: %.2f Ohm\n",findSeries(a,n));
printf("Equivalent Parallel resitance: %.2f Ohm",findParallel(a,n));

return 0;
}

float findSeries(float a[], int n)
{
int i =1;
float series = 0;
while(i <= n)
{
series += a[i];
i++;
}
return series;
}

float findParallel(float a[], int n)
{
int i =1;
float parallel = 0;
while(i <= n)
{
parallel += 1.0/a[i];
i++;
}
parallel += 1.0 / parallel;
return parallel;
}
Note: Refer the screenshots for further clarification.

Output:


Related Solutions

You are to write a C++ program which does the following: Reads in the size of...
You are to write a C++ program which does the following: Reads in the size of a list of characters. Reads in the list of characters. Prints the list of characters in the opposite order read in. Prints the list of characters in the order read in. Sorts the list. Prints the sorted list. You may assume there will be no more than 1000 characters in the list. (You should use a constant to make this limit easily changeable.) You...
Write a C++ Program that does the following: As you can see, there is a file...
Write a C++ Program that does the following: As you can see, there is a file named "invoice1_test1.txt". You are to use this file as your input file for your program. Do the following: 1. Sort the file by last name using an array. You can use any of the sorting algorithms we have previously used in class. You may use the string data type to store text data. 2. Compute the following: a. The total balance due using the...
Program specifics: Write a C++ program that does the following: a. Asks the user for the...
Program specifics: Write a C++ program that does the following: a. Asks the user for the distance to the pin and the depth of the green (both in yards). (Note: The pin is the hole in the green and the depth is the diameter of the green, assuming it is circular.) b. Asks the user for an integer club number from 2 to 10, where 10 is the pitching wedge (this club lifts the ball out of rough, sand, etc)....
Write a program that does the following in C++ 1 ) Write the following store data...
Write a program that does the following in C++ 1 ) Write the following store data to a file (should be in main) DC Tourism Expenses 100.20 Revenue 200.50 Maryland Tourism Expenses 150.33 Revenue 210.33 Virginia Tourism Expenses 140.00 Revenue 230.00 2 ) Print the following heading: (should be in heading function) Store name | Profit [Note: use setw to make sure all your columns line up properly] 3 ) Read the store data for one store (should be in...
Write a C program that does the following. (a) Start with comment statements at the top...
Write a C program that does the following. (a) Start with comment statements at the top (before your includes) with the following info: Name, Date (b) Write the following functions: void setupRandArray(int n, int x[], int min, int max) void printArray(int n, int x[], char label[]) float getAverage(int n, int x[]) int getMaximum(int n, int x[]) int getCountInRange(int n, int x[], int min, int max) Note: This function returns the number elements of x that are between min and max...
Write a C++ program that does the following: Read and input file containing the following PersonAName,...
Write a C++ program that does the following: Read and input file containing the following PersonAName, PersonBName, XA,YA, XB, YB where the coordinates of PersonA in a 100 by 100 room is XA, YA and the coordinates of PersonB is XB, YB. Use square root function in cmath sqrt() to calculate the shortest distance between two points. A file will be uploaded in this assignment that will list coordinates of two people. The program should use a function call that...
Write a program in C that does the following: 1. Declares an array called numbers_ary of...
Write a program in C that does the following: 1. Declares an array called numbers_ary of 6 integer numbers. 2. Declares an array called numbers_ary_sq of 6 integer numbers. 3. Reads and sets the values of numbers_ary from the keyboard using a loop. 4. Sets the values of numbers_ary_sq to the square of the values in numbers_ary using a loop. 5. Displays the values of numbers_ary and the values of numbers_ary_sq beside each other using a loop. Example Output Assume...
Program this in C thank you PROBLEM DESCRIPTION: Write a program to implement the following requirement:...
Program this in C thank you PROBLEM DESCRIPTION: Write a program to implement the following requirement: The program will read from standard input two things - a string str1 on the first line of stdin (this string may be an empty string) - a string str2 on the second line of stdin (this string may be an empty string) Note that stdin does not end with '\n'. The program will output a string that is the concatenation of string str1...
Technology is becoming more and more complicated every year. As technology becomes more complicated new security...
Technology is becoming more and more complicated every year. As technology becomes more complicated new security measures are required in order to protect individuals from theft. Most people do not understand how simple devices such as debit/card cards and online bill pay work, so how can they effectively protect themselves from theft. I believe we have reached a point in technology where most of our financial transactions are done over wire and not actually completed using tangible currency. In-fact only...
Program must be in C++! Write a program which: Write a program which uses the following...
Program must be in C++! Write a program which: Write a program which uses the following arrays: empID: An array of 7 integers to hold employee identification numbers. The array should be initialized with the following values: 1, 2, 3, 4, 5, 6, 7. Hours: an array of seven integers to hold the number of hours worked by each employee. payRate: an array of seven doubles to hold each employee’s hourly pay rate. Wages: an array of seven doubles to...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT