Skip to content
  • P
    Projects
  • G
    Groups
  • S
    Snippets
  • Help

otsall / iax0583

  • This project
    • Loading...
  • Sign in
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 bba83b74 authored 6 years ago by otsall's avatar otsall
Browse files
Options
  • Browse Files
  • Download
  • Email Patches
  • Plain Diff

c program of homework1

parent 0defa4ca master
Hide whitespace changes
Inline Side-by-side
Showing with 52 additions and 0 deletions
  • homework1/homework1ottSalla.c
homework1/homework1ottSalla.c 0 → 100644
View file @ bba83b74
#include <stdio.h> //using only stdio.h and not math.h for powers to make the program more lightweight
float function(float x){//this is the function itself, returns the value when given the input; a function of a function
return (4*x*x*x + 3*x*x + 2*x - 4) / (2 + 1/x);
}
int main(){
float x, // input of the function, called A in the task description, using x as it is in the original function
value, //the value of the function
H, //the step
YM;//minimum value of function
int i = 0;//for counting the number of executions of the function
//setup for the calculations
printf("this program calculates the function y = (4*x*x*x + 3*x*x + 2*x - 4) / (2 + 1/x) a maximum of 15 times\n");
printf("please input starting value\n");
scanf("%f", &x); //scanning the starting value
printf("please input the step (has to be larger than 0)\n");
scanf("%f", &H);//scanning the step
while(H <= 0){//making sure it's bigger than 0, if not, prompts the user again.
printf("the step has to be larger than 0\n");
scanf("%f", &H);
}
printf("please input the lower function value\n");
scanf("%f", &YM);//scanning the lower limit
while(i < 15){//starts the loop, exits on the 16th time
if(x == -0.5 || x == 0){ //in these cases the function would divide by 0 and that is not acceptable
printf("if x = %f y = not available\n", x);
}else{
value = function(x);//the function
if(value >= YM){
printf("if x = %f y = %f\n", x, value);//if the value is lower than YM, prints the value of the function
}else{
printf("lower limit of function exceeded");
break;//breaks the loop when the value is under the lower limit
}
}
x = x + H; //increases the input by step
i++; //counts the executions of the function
}
return 0;
}
This diff is collapsed. Click to expand it.
  • Write
  • Preview
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