USE C ONLY NOT C The following equation describes the voltag
USE C ONLY NOT C++
The following equation describes the voltage of a capacitor in a certain RC circuit as it is charging from a starting value of 0 volts to a final value of 10 volts: v = 10 - 10e^-15t Write a program to print a table of time and corresponding voltage values. In function main, prompt the user to enter a limiting voltage greater than 0 and less than 10 volts for the table and use a while or do while input validation loop to prompt the user to re-enter the limiting voltage value if it is outside the range between 0 and 10. Call a function to print a table of time and voltage values from t = 0 up until the time at which the voltage reaches the desired value. The only function parameter will be the limiting voltage value. Include column headings. Use a while loop to print the table. Print values at time intervals of 0.005 seconds. Print values only as long as the voltage is less than the limiting voltage input by the user (and passed as a function parameter). In the table, place time values in the column on the left and voltage values in the column on the right. Print the table using 3 digits after the decimal point for time and 5 digits after the decimal point for voltage. Test with a limiting voltage value of 6.3 volts.Solution
// C code
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <math.h>
void printTable(double voltage)
{
double t = 0;
double currentVoltage;
printf(\"\ Time\\tVoltage\ \");
while(1)
{
currentVoltage = 10-10*exp(-1*15*t);
printf(\"%0.3lf\\t%0.5lf\ \",t,currentVoltage);
t = t + 0.005;
if(currentVoltage >= voltage)
break;
}
}
int main()
{
double voltage;
while(1)
{
printf(\"Enter a limiting voltage: \");
scanf(\"%lf\",&voltage);
if(voltage > 0 && voltage < 10)
break;
else
printf(\"Voltage must be greater than 0 and less than 10\ \");
}
printTable(voltage);
return 0;
}
/*
output:
Enter a limiting voltage: 11
Voltage must be greater than 0 and less than 10
Enter a limiting voltage: -1
Voltage must be greater than 0 and less than 10
Enter a limiting voltage: 6.3
Time Voltage
0.000 0.00000
0.005 0.72257
0.010 1.39292
0.015 2.01484
0.020 2.59182
0.025 3.12711
0.030 3.62372
0.035 4.08445
0.040 4.51188
0.045 4.90844
0.050 5.27633
0.055 5.61765
0.060 5.93430
0.065 6.22808
0.070 6.50062
*/

