this is the question:
Write a C program that will request the user to input the values for R,L,and C and plot the a graph of current ,I, against frequency . The range for the frequency axis should be automatically selected based on the resonance frequency of the circuit.

Recommended Answers

All 3 Replies

And? What have you tried? Please note that our rules disallow posting homework questions with no proof of effort as if you wanted us do write it for you.

here is my coding

#include<stdio.h>
#include<math.h>
#define pi 3.142

double current(double);
double frequency(double,double);

void main ()
{
    double r,l,c,i;
    double f;
    printf("Enter the value of R(unit in ohm):\n");
    scanf("%lf",&r);
    printf("Enter the value of L(unit in henry):\n");
    scanf("%lf",&l);
    printf("Enter the value of C(unit in farad):\n");
    scanf("%lf",&c);
    i=current(r);
    printf("the value of I,current:%f ampere\n",i);
    f=frequency(l,c);
    printf("the value of f,frequency:%f hertz\n",f);
}

double current(double r)
{
    double v=240;
    double i;
    i=v/r;
    return i;
}

double frequency(double l,double c)
{
    double f=0.0;
    double s=0.0,result;
    s=l*c;
    result=sqrt(s);
    f=1/(2*pi*result);
    return f;
}

my problem is how to plot the graph?

Member Avatar for Mouche

Assuming this is for a class, did your professor use or recommend a plotting library?

If not, you could do a rough graph in ASCII like this:

     5        #     
     4        ##     
 I   3        ##     #
(mA) 2        ##     #
     1        ##     #
     0 ################
       0     500     1k
           Freq (Hz)

You would just have to come up with some math to simplify the data to individual ASCII blocks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.