Commit acd86157 by chazog

Delete desmondhomework1.c

parent 86f0fe44
Showing with 0 additions and 73 deletions
#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("\nNumber\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\ty(x) = %.2f\n", num, i, y);
} else {
printf("%d. \t\t x=%.f \t\t\ty(x) = not available \n", num, i, y); // If function value exceeds B, then y(x) is not available/not defined.
}
}
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment