Commit d8916e69 by unknown

rename programming homework 1

parent 093b3bd5
/*
* File: homework1.c
* Author: Tran Minh Huy Vu
*
* Created on October 4, 2018, 1:50 PM
*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
void createTable() {
printf("╒═══╤═══════════════╤═══════════════╕\n");
printf("│ nr│ x │ y │\n");
printf("╞═══╪═══════════════╪═══════════════╡\n");
}
int number = 1;
void addToTable(float a, float b) {
if (isnan(b)) {
if (a < 10) {
printf("│ %d │ %f │ NaN │\n", number, a);
} else if (a < 100) {
printf("│ %d │ %f │ NaN │\n", number, a);
}
} else if (number < 10) {
if (a < 10) {
if (b < 10) printf("│ %d │ %f │ %f │\n", number, a, b);
else if (b < 100) printf("│ %d │ %f │ %f │\n", number, a, b);
} else if (a < 100) {
if (b < 10) printf("│ %d │ %f │ %f │\n", number, a, b);
else if (b < 100) printf("│ %d │ %f │ %f │\n", number, a, b);
}
} else if (number < 100) {
if (a < 10) {
if (b < 10) printf("│%d │ %f │ %f │\n", number, a, b);
else if (b < 100) printf("│ %d│ %f │ %f │\n", number, a, b);
} else if (a < 100) {
if (b < 10) printf("│%d │ %f │ %f │\n", number, a, b);
else if (b < 100) printf("│%d │ %f │ %f │\n", number, a, b);
}
}
number++;
}
void endTable() {
printf("╘═══╧═══════════════╧═══════════════╛");
}
int main() {
float x, y, lim, incre;
printf("Please input starting value: ");
scanf("%f", &x);
printf("Please input increment value: ");
scanf("%f", &incre);
if (incre <= 0) {
printf("Increment have to be > 0");
return 1;
}
printf("Please input limit value: ");
scanf("%f", &lim);
if (lim <= x) {
printf("Limit have to be bigger than starting value");
return 1;
}
printf("Result for: ln(x + 5) / sqrt(7 + 5x + x^2)\n\n");
createTable();
int tooMuch = 0;
for (float i = 0; i < lim && !tooMuch; i = i + incre) {
y = log(i + 5) / sqrt(7 + 5*i + i*i);
addToTable(i, y);
if (isnan(y)) y = lim - 1;
if (number >= 16) tooMuch = 1;
}
endTable();
return (EXIT_SUCCESS);
}
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