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
75dbf9f8
authored
Dec 16, 2018
by
chazog
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Homework1
parent
edbd60fb
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
85 additions
and
0 deletions
Homeworks/desmondhomework1.c
Homeworks/desmondhomework1.c
0 → 100644
View file @
75dbf9f8
#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).
*/
int
main
(
void
)
{
float
A
,
B
,
H
,
C
;
// Variable declaration
int
N
;
printf
(
"Enter starting value (A): "
);
// User inputs start value
scanf
(
"%f"
,
&
A
);
printf
(
"Enter stop value (B): "
);
// User inputs stop value
scanf
(
"%f"
,
&
B
);
do
{
printf
(
"Enter steps coefficient (C): "
);
// User inputs coefficient of step
scanf
(
"%f"
,
&
C
);
if
(
C
<
1
)
// checks if the step value is greater than 0.
{
printf
(
"Step coefficient must be greater than or equals to 1!
\n
"
);
}
}
while
(
C
<
1
);
do
{
printf
(
"Enter Total Number of Points (N): "
);
// User inputs number of iterations desired
scanf
(
"%d"
,
&
N
);
if
(
N
<=
0
||
N
>
15
)
// checks if the number of points is less than or equal to 0 or if the value is greater than 15.
{
printf
(
"Number of points must be greater than 0 and less or equals to 15!
\n
"
);
}
}
while
(
N
<=
0
||
N
>
15
);
do
{
printf
(
"Enter Step Value (H): "
);
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
;
float
x
;
float
sequenceSum
;
for
(
int
i
=
0
;
i
<=
N
;
i
++
)
// For loop is dependent on the user's input of 'N'.
{
if
(
i
==
0
)
{
x
=
A
;
sequenceSum
=
x
;
}
else
{
x
=
sequenceSum
+
(
H
*
pow
(
C
,
i
-
1
));
// equation for each iteration of X[n]
sequenceSum
=
x
;
}
float
y
=
(
14
*
pow
(
x
,
3
)
+
7
*
pow
(
x
,
2
)
-
x
+
20
)
/
(
pow
(
x
,
2
)
-
4
*
x
);
//Equation for y(x)
num
++
;
if
(
y
<=
B
)
// Satisfies the condition "Until function value exceeds B".
{
printf
(
"%d.
\t\t
x=%.f
\t\t
y(x) = %.2lf
\n
"
,
num
,
x
,
y
);
// prints out the values of y(x) equivalent to the x values
}
else
{
printf
(
"%d.
\t\t
x=%.f
\t\t\t
y(x) = N/A
\n
"
,
num
,
x
,
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