Ohm's law in C program?

We were given the task of creating a C program (I'm using onlinegdb.com) that displays the correct values ​​when run. Given the values ​​of 33V and the resistors:

R1=blue yellow red silver

R2=purple white orange gold

R3=red red red silver

R4=grey white red gold

R5=red green brown silver

R6=yellow orange brown gold

R7=brown black black silver

R7=red blue brown gold

We're supposed to write C code that displays the results when you click "Run," but I have no idea what kind of code to write because I don't know anything about C or programming languages, and we haven't been told how to proceed.

This is what the circuit looks like:

https://ibb.co/J7cCTH7

PS: I have reposted this question with more details.

(2 votes)
Loading...

Similar Posts

Subscribe
Notify of
8 Answers
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
JulianOnFire
1 year ago

Hello

pretty heavy task for the first time with C

First you need to determine the resistance values based on their color codes. Then you can use the Ohm Law to calculate the current through any resistance when a voltage of 33V is applied.

In the code, you need to define the color coding first. After that, you can write a function that calculates the balance and gives you the value back. It’s as if you’re programming a TR.

If you can’t get any further, I’ll try to help you, but I’d have to think about it.

JulianOnFire
1 year ago
Reply to  InfinityIs

got it and tested. Works perfectly. Don’t know how exactly I can explain this to you

JulianOnFire
1 year ago

I have sent you

ElvanL77
1 year ago

So…

First you need variabels…

So type and then the name you want to forgive. Float, by the way. Variabel search guys.

https://learn.microsoft.com/de-de/visualstudio/get-started/csharp/tutorial-console?view=vs-2022

//Variabeln einrichten
float r = 10.25;
float i = 5.30;
float u;

u = i * r; // eigentliche Rechnung

Console.WriteLine (u); //Ergebniss ausgeben
Console.ReadKey();
tunik123
1 year ago

Since I find the task quite difficult, I’ve been dealing with it too. The determination of the resistance values from the color code is not suitable for beginners.

#include    
#include    
#include    
#include    

//-------------------------------------------------------------
static double Ring(const char *Farbe)
//-------------------------------------------------------------
{
    int iIdx;

    static const char *aFarben[] = {
        "schwarz", "braun", "rot",  "orange", "gelb",
        "gruen",   "blau",  "lila", "grau",   "weiss" };

    for(iIdx = 0; iIdx < 10; iIdx++) {
        if(strcmp(Farbe,aFarben[iIdx]) == 0) return (double)iIdx;
    }
    fprintf(stderr,"*** Farbe %s unbekannt ***\n", Farbe);
    assert(0);
    return(0.0);
}


//-------------------------------------------------------------
static double Wert(const char *Farbe1, const char *Farbe2,
  const char *Farbe3)
//-------------------------------------------------------------
// Widerstandswert aus den Farben von dreei Ringen ermitteln
{
    return (10 * Ring(Farbe1) + Ring(Farbe2))
    * pow(10.0, Ring(Farbe3));
}

//--------------------------------------------------------------
static double Par(double Rx, double Ry)
//--------------------------------------------------------------
// Parallelschaltung zweier Widerstaende berechnen
{
    return 1.0 / (1.0 / Rx + 1.0 / Ry);
}

//--------------------------------------------------------------
int main(int argc, char **argv)
//--------------------------------------------------------------
{
    const double R1 = Wert("blau",  "gelb",    "rot");
    const double R2 = Wert("lila",  "weiss",   "orange");
    const double R3 = Wert("rot",   "rot",     "rot");
    const double R4 = Wert("grau",  "weiss",   "rot");
    const double R5 = Wert("rot",   "gruen",   "braun");
    const double R6 = Wert("gelb",  "orange",  "braun");
    const double R7 = Wert("braun", "schwarz", "schwarz");
    const double R8 = Wert("rot",   "blau",    "braun");

    const double Uges = 33.0;

    double R12, R124, R5678, R1234, Rges;
    double U12, U4, U5, U6, U7, U8, I5678;

    printf("R1 = %5.0lf\n", R1);
    printf("R2 = %5.0lf\n", R2);
    printf("R3 = %5.0lf\n", R3);
    printf("R4 = %5.0lf\n", R4);
    printf("R5 = %5.0lf\n", R5);
    printf("R6 = %5.0lf\n", R6);
    printf("R7 = %5.0lf\n", R7);
    printf("R8 = %5.0lf\n", R8);
    printf("\n");

    R12   = Par(R1, R2);
    R124  = R12 + R4;
    R1234 = Par(R124, R3);
    R5678 = R5 + R6 + R7 + R8;
    Rges  = Par(R1234, R5678);

    U12   = Uges * R12 / R124;
    U4    = Uges * R4  / R124;
    U5    = Uges * R5  / R5678;
    U6    = Uges * R6  / R5678;
    U7    = Uges * R7  / R5678;
    U8    = Uges * R8  / R5678;

    printf("U1 = %6.3lf\n", U12);
    printf("U2 = %6.3lf\n", U12);
    printf("U3 = %6.3lf\n", Uges);
    printf("U4 = %6.3lf\n", U4);
    printf("U5 = %6.3lf\n", U5);
    printf("U6 = %6.3lf\n", U6);
    printf("U7 = %6.3lf\n", U7);
    printf("U8 = %6.3lf\n", U8);
    printf("\n");

    return 0;
}