如何创建将输入除以2的收缩函数?

时间:2019-02-20 18:46:34

标签: c shrink

使用下面的代码,我如何创建将输入除以2的收缩函数?我对这些东西还很陌生,所以我尝试做一些没有运气的操作,例如floatingrinkle(a / 2)。

#include <stdio.h>

void printHelp () {
 printf ("\n");
 printf ("a: a(x) = x*x\n");
 printf ("b: b(x) = x*x*x\n");
 printf ("c: c(x) = x^2 + 2*x + 7\n");
 printf ("q: quit\n");
}

void a(float x) {
float v = x*x;
printf (" a(%.2f) = %.2f^2 = %.2f\n", x, x, v);
} // end function a
void b(float x) {
float v = x*x*x;
 printf (" a(%.2f) = %.2f^3 = %.2f\n", x, x, v);
} // end function b
void c(float x) {
 float v = x*x + 2*x + 7;
 printf (" c(%.2f) = %.2f^2 + 2*%.2f + 7 = %.2f\n",
 x, x, x, v);
} // end function c
int menu () {
 char selection;
 float x;
 printHelp ();
 scanf ("%s", &selection);
 if (selection == 'q') return 1;
 scanf ("%f", &x);
 if (selection == 'a') a(x);
 if (selection == 'b') b(x);
 if (selection == 'c') c(x);
 return 0;
} // end function menu
int main() {
 while (menu() == 0);
 printf ("... bye ...\n");
 return 0;
} // end main

1 个答案:

答案 0 :(得分:1)

去了,想要的收缩功能

1-将x除以2(将其缩小)

2正确显示

void shrink(float x) {
float v = x/2.0;
printf (" shrink(%.2f) = %.2f/2 = %.2f\n", x, x, v);
}