PDA

View Full Version : C+........................Basi c c program



vennpuraa
09-19-2006, 12:17 AM
hi
hru


#include<stdio.h>
#include<conio.h>
#include<math.h>


#define PI 3.14169
#define VI 5
#define L 4.3e-4
#define C 5.1e-6
#define R 5

float calculate_Xl( float fc);
float calculate_Xc( float fc);

int main()
{
float fc,result,answer,v;
clrscr();
printf("Please enter the frequency==> ");
scanf("%f",&fc);
result=calculate_Xl(fc);
answer=calculate_Xc(fc);
v=(VI*R)/sqrt((result-answer)*(result-answer)+R*R);
printf("The voltage out is %fvolts",v);
getch();
}
float calculate_Xl( float fc)
{
float a;
a=2*PI*fc*L;
return a;
}
float calculate_Xc( float fc)
{
float a;
a=1/(2*PI*fc*C);
return a;
}

"Change the above program to input different values of R and out the frequency f where Vo is maximum. Use freequencies from 10 to 1 000,000" Hertz with an increment of 10 "'


to get the R values i have to ask the user to input the value..........

how do change the frequency??.i mean ho do i create loop for that??? ( i have to use for loop rite)

help me pls

thanks in advance
:)

Narayana
09-19-2006, 12:51 AM
remove the #define for R,
instead of printf("Please enter the frequency==> ");
scanf("%f",&fc);

use

printf("Please enter the R==> ");
scanf("%f",&R);

for(float fc=10;fc<1000000;fc+=10){ //check if range of float is enough...
result=calculate_Xl(fc);
answer=calculate_Xc(fc);
v=(VI*R)/sqrt((result-answer)*(result-answer)+R*R);

if(fc ==10) //first time, make vmax=v;
vmax = v;
else{
if(v>vmax)
vmax = v;
}
//now prit vmax
}
if thats what you want...

vennpuraa
09-19-2006, 03:50 PM
thanks friend