Computer Science»C Program»Find Equivalent Capacitance of Parallel Combination of Capacitive Circuit
Program :
#include<stdio.h>
int main()
{
float c[10], num, Cp = 0;
int i;
printf("Enter the number of capacitors : ");
scanf("%f", &num);
printf("nEnter value of each capacitor : ");
for (i = 0; i < num; i++) {
printf("nC%d : ", i + 1);
scanf("%f", &c[i]);
}
for (i = 0; i < num; i++) {
Cp = Cp + c[i];
}
printf("nEquivalent parallel capacitance : %f", Cp);
return (0);
}
Output :
Enter the number of capacitors : 3
Enter value of each capacitor :
C1 : 1
C2 : 5
C3 : 8
Equivalent parallel capacitance : 14.000000
Computer Science » C Program » Find Equivalent Capacitance of Series Combination of Capacitive Circuit Program : [php]#include<stdio.h> int main() { float c[10], num, Cs = 0; int i; printf("Enter the number of capacitors : "); scanf("%f", &num); printf("nEnter value of each capacitor : "); for (i = 0; i < num; i++) { printf("nC%d : ", i + 1); scanf("%f", &c[i]); } for (i = 0; i < num; i++) { Cs = Cs + (1.0 / c[i]); } Cs = 1.0 / Cs; printf("nEquivalent series capacitance : %f", Cs); return (0); }[/php] Output : [php]Enter the number of capacitors : 3 Enter value of each capacitor : C1 : 1 C2 : 1 C3 : 1 Equivalent series capacitance : 0.333333[/php]
Computer Science » C Program » Find Equivalent Resistance of Parallel Combination of Resistive Circuits Program : [php]#include<stdio.h> int main() { int r, num, i; float eqr = 0, temp; printf("Enter the number of resistances : "); scanf("%d", &num); printf("nEnter value of each resistance : "); scanf("%f", &eqr); for (i = 1; i < num; i++) { scanf("%d",&r); temp=(1/eqr)+((1/(float)r)); eqr=(1/temp); } printf("nEquivalent series resistance : %f", eqr); return (0); }[/php] Output : [php]Enter the number of resistances : 3 Enter value of each resistance : 100 100 50 Equivalent series resistance : 25.000000[/php]
Computer Science » C Program » Searching Element in an Array Program : [php]#include<stdio.h> int main() { int a[30], element, num, i; printf("nEnter no of elements : "); scanf("%d", &num); printf("nEnter the values : "); for (i = 0; i < num; i++) { scanf("%d", &a[i]); } //Read the element to be searched printf("nEnter the element to be searched : "); scanf("%d", &element); //Search starts from the zeroth location i = 0; while (i < num && element != a[i]) { i++; } //If i < num then Match found if (i < num) { printf("nNumber found at the location : %d", i + 1); } else { printf("nNumber not found."); } return (0); }[/php] Output 1: [php]Enter no of elements : 5 Enter the values : 10 20 30 40 50 Enter the element to be searched : 30 Number found at the location : 3[/php] Output 1: [php]Enter no of elements : 5 Enter the values : 10 20 30 40 50 Enter the element to be searched : 60 Number not found.[/php]
Computer Science » C Program » Find greatest in 3 numbers Program : [php]#include<stdio.h> int main() { int a, b, c; printf("nEnter value of a, b & c : "); scanf("%d %d %d", &a, &b, &c); if ((a > b) && (a > c)) printf("na is greatest"); if ((b > c) && (b > a)) printf("nb is greatest"); if ((c > a) && (c > b)) printf("nc is greatest"); return(0); }[/php] Output : [php]Enter value for a,b & c : 12 16 20 c is greatest[/php]
Computer Science » C Program » Find Equivalent Resistance of Series Combination of Resistive Circuits Program : [php]#include<stdio.h> int main() { int r[10], num, i, Rs = 0; printf("Enter the number of resistances : "); scanf("%d", &num); printf("nEnter Value of each resistance : "); for (i = 0; i < num; i++) { printf("nR%d : ", i + 1); scanf("%d", &r[i]); } for (i = 0; i < num; i++) { Rs = Rs + r[i]; } printf("nEquivalent series resistance : %d", Rs); return (0); }[/php] Output : [php]Enter the number of resistances : 5 Enter Value of each resistance : R1 : 1 R2 : 2 R3 : 3 R4 : 4 R5 : 5 Equivalent series resistance : 15[/php]