Advertisement
Guest User

Untitled

a guest
Sep 20th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.08 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3. #include <strings.h>
  4.  
  5. void info(){
  6.     printf("171RDB133\n");
  7.     printf("Lauris Štekels\n");
  8.     printf("7.grupa\n");
  9. }
  10.  
  11. float calcA(float x) {
  12.     return logf(2 * x - 3);
  13. }
  14.  
  15. float calcB(float x) {
  16.     return (4 * x) / (x * x - 9);
  17. }
  18.  
  19. void function1(float a, float b) {
  20.     float result = logf(fabsf(b) - sqrtf(a));
  21.     printf("%.3f\n", result);
  22. }
  23.  
  24. void function2(float a, float b) {
  25.     float result = ((a + 1) / 10) - 18 * a * b;
  26.     printf("%.3f\n", result);
  27. }
  28.  
  29. void mainTask() {
  30.     int validation, trash;
  31.     float x, a, b;
  32.  
  33.     printf("Ievadiet x: ");
  34.  
  35.     validation = scanf("%f", &x);
  36.     trash      = scanf("%c", &x);
  37.  
  38.     if (validation != 1) {
  39.         printf("Invalid input!\n");
  40.     } else {
  41.         a = calcA(x);
  42.         b = calcB(x);
  43.         a < fabsf(b) ? function1(a, b) : function2(a, b);
  44.     }
  45.  
  46. }
  47.  
  48. int main() {
  49.     info();
  50.     char cont = 'y';
  51.     while (strcasecmp(&cont, "y") == 0) {
  52.         mainTask();
  53.         printf("Continue? (y or Y)\n");
  54.         scanf("%s", &cont);
  55.     }
  56.     return 0;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement