# Electronics - DC Parallel Resistors using a vector

Page 1 of 1

## 0 Replies - 2005 Views - Last Post: 05 May 2012 - 08:58 AM

### #1 az.tech Reputation: 0
• Posts: 6
• Joined: 21-February 09

# Electronics - DC Parallel Resistors using a vector

Posted 05 May 2012 - 08:58 AM

Description: Compile & runEnter the supply voltage
Enter the number of resistors in the circuit
Enter values for those resistors
Calculate the equivalent resistance, total current and branch currents
```#include<iostream>
#include<vector>

using namespace std;

int main()
{
// Declare variables & set parameters for calculations
vector <float> pr;
int n;
float resistance, par_Resistance, voltage, current, percent_I;
cout << "Enter the supply voltage." << endl;
cin >> voltage;
cout << "Enter number of parallel resistors in the circuit." << endl;
cin >> n;
cout << endl;

// Create a vector & resize it to enter & store the resistor values
pr.resize(n);
for (int i = 0; i < n; i++)
{
cout << "Enter the value of R" << i + 1 << endl;
cin >> pr[i];
}
//Calculate & display the equivelent parallel resistance
for (int i = 0; i < n; i++)
{
resistance = 1/pr[i];
par_Resistance += resistance;
}
resistance = 1/par_Resistance;
cout << endl;
cout << "The equivelent parallel resistance is " << resistance << " ohms." << endl;

//Calculate current through the entire circuit
current = voltage / resistance;
cout << "The total current is " << current << " amps." << endl << endl;

// Calculate the branch currents through each resistor
for (int i = 0; i < n; i++)
{
percent_I = (resistance / pr[i]) * current;
cout << "Current through R" << i + 1 << " is " << percent_I << " amps." << endl;
}
}

```

Is This A Good Question/Topic? 0

Page 1 of 1

 .related ul { list-style-type: circle; font-size: 12px; font-weight: bold; } .related li { margin-bottom: 5px; background-position: left 7px !important; margin-left: -35px; } .related h2 { font-size: 18px; font-weight: bold; } .related a { color: blue; }