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 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 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 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...
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...
Write a program in java processing. Write a program that does the following: · Assume the...
Write a program in java processing. Write a program that does the following: · Assume the canvas size of 500X500. · The program asks the user to enter a 3 digit number. · The program then checks the value of the first and last digit of the number. · If the first and last digits are even, it makes the background green and displays the three digit number at the mouse pointer. · If the two digits are odd, it...
Using C++ Write One one single program with two or more functioncallsWrite a C++...
Using C++ Write One one single program with two or more function callsWrite a C++ function, smallest Index, that takes as parameters an int array and its size and returns the index of the smallest element in the array. Also the program should test the function.Write another function that prompts the user to input a string and outputs the string in uppercase letters. You must use a character array to store the string.
Write a c++ program that does the following, read temperatures from a file name temp.txt into...
Write a c++ program that does the following, read temperatures from a file name temp.txt into an array, and after reading all the temperatures, output the following information: the average temperature, the minimum temperature, and the total number of temperatures read. Thank you!
Write a C program that creates a toy scheduler for the child processes in part A....
Write a C program that creates a toy scheduler for the child processes in part A. This program takes as input the number of processes, and all of the PIDs that are being echoed. HINT: Look up redirecting echo output. The program will schedule the ”processes” (note that these are not true processes, this is a toy system. You are effectively only scheduling echo statements). The result of the scheduler will be to echo the PID and current system time...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT