Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
chazog
/
iax0583
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
acd86157
authored
Dec 16, 2018
by
chazog
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Delete desmondhomework1.c
parent
86f0fe44
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
0 additions
and
73 deletions
desmondhomework1.c
desmondhomework1.c
deleted
100644 → 0
View file @
86f0fe44
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
/*
* Name: Azogu, Chibuzo Desmond
* Variant: Method 5, Function 48
* Description: The program calculates the function y(x) in already defined points. It allows user input for;
starting value A, stop value B, steps coefficient C and step value H.
It then calculates the function y(x) until function value exceeds B
and N <= 15 (Where N = number of total points).
*/
float
findX
(
int
i
,
int
n
,
int
C
,
float
A
,
float
H
)
// This function calculates the argument of X[n]
{
if
(
n
==
1
)
return
A
;
else
return
A
+
(
i
*
H
*
pow
(
C
,
n
-
1
));
// equation for each iteration of X[n]
}
float
findY
(
float
x
)
{
// This function calculates the function y(x)
return
(
14
*
pow
(
x
,
3
)
+
7
*
pow
(
x
,
2
)
-
x
+
20
)
/
(
pow
(
x
,
2
)
-
4
*
x
);
//Equation for y(x)
}
int
main
(
void
)
{
float
i
,
A
,
B
,
H
,
C
;
// Variable declaration
int
N
;
printf
(
"Enter starting value: "
);
// User inputs start value
scanf
(
"%f"
,
&
A
);
printf
(
"Enter stop value: "
);
// User inputs stop value
scanf
(
"%f"
,
&
B
);
printf
(
"Enter steps coefficient: "
);
// User inputs coefficient of step
scanf
(
"%f"
,
&
C
);
printf
(
"Enter Total Number of Points: "
);
// User inputs number of iterations desired
scanf
(
"%d"
,
&
N
);
do
{
printf
(
"Enter Step Value: "
);
scanf
(
"%f"
,
&
H
);
if
(
H
<=
0
)
// checks if the step value is greater than 0.
{
printf
(
"Step value must be greater than 0!
\n
"
);
}
}
while
(
H
<=
0
);
printf
(
"
\n
Number
\t\t
Argument(x)
\t\t
Function y(x)
\n
"
);
int
num
=
0
;
int
n
;
for
(
i
=
A
;
i
<
B
;
i
+=
C
)
// For loop is dependent on the user's input of 'N', to satisfy N <= 15 in the question.
{
float
x
=
findX
(
i
,
A
,
C
,
H
,
n
);
// The function findX is called to calculate X for each iterations of 'i'
float
y
=
findY
(
i
);
// The function findY is called to calculate function y(x) for each iterations of 'i'
num
++
;
if
(
y
<=
B
)
// Satisfies the condition "Until function value exceeds B".
{
printf
(
"%d.
\t\t
x=%.f
\t\t\t
y(x) = %.2f
\n
"
,
num
,
i
,
y
);
}
else
{
printf
(
"%d.
\t\t
x=%.f
\t\t\t
y(x) = not available
\n
"
,
num
,
i
,
y
);
// If function value exceeds B, then y(x) is not available/not defined.
}
}
return
0
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment