C
This commit is contained in:
parent
4ecfebcd1b
commit
04d946e28c
30
DeitelC/Chapter3/CheckConstantEOverX.c
Normal file
30
DeitelC/Chapter3/CheckConstantEOverX.c
Normal file
@ -0,0 +1,30 @@
|
||||
#include <stdio.h>
|
||||
|
||||
double powerFun(double base, int exponent) {
|
||||
double result = 1.0;
|
||||
for (int i = 0; i < exponent; i++) {
|
||||
result *= base;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
int userData;
|
||||
printf("Please Enter x (in E^x): ");
|
||||
scanf("%d", &userData);
|
||||
|
||||
double constant = 2.0; // Initialize constant as a double
|
||||
double counter = 1.0; // Initialize counter to 1.0
|
||||
double data = 1.0; // Initialize data to 1.0
|
||||
|
||||
for (int i = 1; i <= userData; i++) {
|
||||
data *= constant; // Update data by multiplying with constant
|
||||
double term = powerFun(userData, i) / data; // Calculate the term for the current iteration
|
||||
counter += term; // Add the term to the counter
|
||||
printf("counter: %f\n", counter);
|
||||
}
|
||||
|
||||
printf("e^%d = %f\n", userData, counter);
|
||||
|
||||
return 0;
|
||||
}
|
17
DeitelC/Chapter3/ConstantE.c
Normal file
17
DeitelC/Chapter3/ConstantE.c
Normal file
@ -0,0 +1,17 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main(void) {
|
||||
float constant = 2;
|
||||
float counter = 2;
|
||||
float data = 1;
|
||||
float check = 1;
|
||||
while(constant <= 40) {;
|
||||
data = constant * data;
|
||||
check = 1/data;
|
||||
counter = check + counter;
|
||||
printf("%s %f\n","counter :", counter);
|
||||
|
||||
constant++;
|
||||
}
|
||||
return 0;
|
||||
}
|
30
DeitelC/Chapter3/ConstantEOverX.c
Normal file
30
DeitelC/Chapter3/ConstantEOverX.c
Normal file
@ -0,0 +1,30 @@
|
||||
#include <stdio.h>
|
||||
int powerFun(int userData, int i) {
|
||||
float result = 1.0;
|
||||
while (i > 0) {
|
||||
result *= userData;
|
||||
i--;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
double constant = 2;
|
||||
double counter = 2;
|
||||
double data = 1;
|
||||
float check = 1;
|
||||
int userData;
|
||||
int i = 1;
|
||||
printf("%s\n","Please Enter x (in E^x): ");
|
||||
scanf("%d", &userData);
|
||||
while(i <= userData) {
|
||||
data = constant * data;
|
||||
check = powerFun(userData, i)/data;
|
||||
counter = check + counter;
|
||||
printf("%s %f\n","counter :", counter);
|
||||
printf("%s %d\n","PowerFun:", powerFun(userData, i));
|
||||
i++;
|
||||
constant++;
|
||||
}
|
||||
return 0;
|
||||
}
|
Binary file not shown.
BIN
DeitelC/Chapter4/a.exe
Normal file
BIN
DeitelC/Chapter4/a.exe
Normal file
Binary file not shown.
14
DeitelC/Chapter4/sum99.c
Normal file
14
DeitelC/Chapter4/sum99.c
Normal file
@ -0,0 +1,14 @@
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
int main(void) {
|
||||
int sum = 0;
|
||||
int count = 1;
|
||||
|
||||
for(;count<=99;count+=2) {
|
||||
sum += count;
|
||||
}
|
||||
printf("%d\n", sum);
|
||||
printf("%.2f\n", pow(2.5,3));
|
||||
return 0;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user