1. Within a complex electronic circuit, the voltage (V) varies with time (t) acc
ID: 3738421 • Letter: 1
Question
1. Within a complex electronic circuit, the voltage (V) varies with time (t) according to the formula 3 12 (2i-l)T it COS where-3 . Write the program in such a manner that the times (t2 and t?) and the number of terms in the series (n, where i-1. 2. .. .. n) are entered as input quantities. Display the values of both times & ti, n, the voltage Vat each time and the change in voltage (AP) for each data set. Include a provision for repeated program execution (for example, by displaying Again? (Y/N) at the end of each calculation, after the results have been displayed. Test your program for the following sets of data -0.5 ?= 0.5 Have the entire program in a loop to allow the user to do a different option(a, b or c) Remember that your program must be stylistically well written as well as mathematically correct. As indicated in the last assignment, your program must include comments, liberal use of whitespace, and proper indentation. In addition, the program should include prompts for the input data, and should display the output in a manner that is clearly labeled and unambiguousExplanation / Answer
Screenshot
-
-----------------------------------------------------------------------------------------------------------------------------------------
Program
//header files
#include <stdio.h>
#include<math.h>
#include <stdlib.h>
//pi value constant
#define PI 3.141593
//main function
int main(void) {
//Variable declaration
int n=0,i=1;
char ch,dec;
float t,t1,t2,v=0,v1=0,v2=0,absilon,deltaV;
//Enter choice a, b,or c
printf("Enter your choice (a,b or c):");
scanf("%c",&ch);
//swich for choice of calculation
switch(ch){
//Question a calculation
case 'a':
printf(" Enter thae value of t :");
scanf("%f",&t);
if(t>-3 && t<3){
printf(" Enter thae value of n:");
scanf("%d",&n);
printf(" t n v");
for(int i=1;i<=n;i++){
v+=(3/2)-((12/pow(PI,2))*(1/pow((2*i-1),2))*cos(((2*i-1)*PI*t)/3));
printf(" %.1f %d %.1f",t,i,v);
}
}
else{
printf(" t value should be between -3 to 3 .");
}
break;
//Question b calculation
case 'b':
printf(" Enter thae value of t :");
scanf("%f",&t);
//printf("%.1f",t);
if(t>-3 && t<3){
printf(" Enter thae value of absilon:");
scanf("%f",&absilon);
while(v<=absilon){
v+=(3/2)-((12/pow(PI,2))*(1/pow((2*i-1),2))*cos(((2*i-1)*PI*t)/3));
n+=1;
}
printf(" The value of t=%.1f , The value of absilon =%.3f , The value of n=%d and The value of voltage=%.1f",t,absilon,n,v);
}
else{
printf(" t value should be between -3 to 3 .");
}
break;
//Question c calculation
case 'c':
printf(" Enter thae value of t1 :");
scanf("%f",&t1);
printf(" Enter thae value of t2:");
scanf("%f",&t2);
if(t1>-3 && t2>-3 && t2<3 && t1<3){
printf(" Enter thae value of n:");
scanf("%d",&n);
printf(" t1 t2 v1 v2 DeltaV");
for(int i=1;i<=n;i++){
v1+=(3/2)-((12/pow(PI,2))*(1/pow((2*i-1),2))*cos(((2*i-1)*PI*t1)/3));
v2+=(3/2)-((12/pow(PI,2))*(1/pow((2*i-1),2))*cos(((2*i-1)*PI*t2)/3));
deltaV=v2-v1;
printf(" %.1f %.1f %.1f %.1f %.1f",t1,t2,v1,v2,deltaV);
}
}
//printf("%.1f",t);
else{
printf(" t value should be between -3 to 3 .");
}
break;
}
//Yes or no question
printf(" Do you want to calculate again (y/n) :");
scanf("%c",&dec);
//Looping if not no
while(dec!='n'){
//Enter choice a, b,or c
printf(" Enter your choice (a,b or c):");
scanf("%c",&ch);
//swich for choice of calculation
switch(ch){
//Question a calculation
case 'a':
printf(" Enter thae value of t :");
scanf("%f",&t);
if(t>-3 && t<3){
printf(" Enter thae value of n:");
scanf("%d",&n);
printf(" t n v");
for(int i=1;i<=n;i++){
v+=(3/2)-((12/pow(PI,2))*(1/pow((2*i-1),2))*cos(((2*i-1)*PI*t)/3));
printf(" %.1f %d %.1f",t,i,v);
}
}
else{
printf(" t value should be between -3 to 3 .");
}
break;
//Question b calculation
case 'b':
printf(" Enter thae value of t :");
scanf("%f",&t);
//printf("%.1f",t);
if(t>-3 && t<3){
printf(" Enter thae value of absilon:");
scanf("%f",&absilon);
while(v<=absilon){
v+=(3/2)-((12/pow(PI,2))*(1/pow((2*i-1),2))*cos(((2*i-1)*PI*t)/3));
n+=1;
}
printf(" The value of t=%.1f , The value of absilon =%.3f , The value of n=%d and The value of voltage=%.1f",t,absilon,n,v);
}
else{
printf(" t value should be between -3 to 3 .");
}
break;
//Question c calculation
case 'c':
printf(" Enter thae value of t1 :");
scanf("%f",&t1);
printf(" Enter thae value of t2:");
scanf("%f",&t2);
if(t1>-3 && t2>-3 && t2<3 && t1<3){
printf(" Enter thae value of n:");
scanf("%d",&n);
printf(" t1 t2 v1 v2 DeltaV");
for(int i=1;i<=n;i++){
v1+=(3/2)-((12/pow(PI,2))*(1/pow((2*i-1),2))*cos(((2*i-1)*PI*t1)/3));
v2+=(3/2)-((12/pow(PI,2))*(1/pow((2*i-1),2))*cos(((2*i-1)*PI*t2)/3));
deltaV=v2-v1;
printf(" %.1f %.1f %.1f %.1f %.1f",t1,t2,v1,v2,deltaV);
}
}
//printf("%.1f",t);
else{
printf(" t value should be between -3 to 3 .");
}
break;
}
//Yes or no question
printf(" Do you want to calculate again (y/n) :");
scanf("%c",&dec);
}
return 0;
}
--------------------------------------------------------------------------------------
Output
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.