c/c++语言开发共享C分段故障中的方程求解器

#include  int main() { printf("choose number"); c(); } c() { printf("1. ax+b=0nn"); printf("2. ax+by+c=0n dx+ey+f=0nn"); int n; scanf("%d", &n); if (n > 3) wrong(); if (n == 1) formula1(); if (n == 2) formula2(); if (n == 3) ; formula3(); } wrong() { printf("Please choose a number between 1 and 3.nn"); c(); } formula1() { printf("ax+b=0n"); printf("Enter your values for a and b respectively, seperated by commasn"); float a, b, x; scanf("%f,%f,%f", &a, &b); x = -b / a; printf("x=-b/an"); printf("=>x=%f", x); question(); } formula2() { printf("ax+by+c=0nndx+ey+f=0n"); printf( "Enter your values for a, b, c, d ,e and f respectively, seperated by commasn"); float a, b, c, d, e, f, x, y; scanf("%f,%f,%f,%f,%f,%f", &a, &b, &c, &d, &e, &f); x = ((f * b) - (c * e)) / ((a * e) - (d * b)); y = ((c * d) - (f * a)) / ((e * a) - (d * b)); printf("=>x=%f", x); printf("nn"); printf("=>y=%f", y); question(); } question() { char t; printf("nnanother equation?ny/n?n"); if (t == 'y') { printf("nnnnn"); c(); } else if (t != 'n') question(); } 

我有这个代码,简而言之就解决了3个方程式。 当您选择任何选项时,它似乎多次运行问题方法,然后由于segmentation fault: 11而退出segmentation fault: 11

有人可以指出我哪里出错了。 我的代码的任何其他帮助将不胜感激

    这是一个问题:

     scanf("%f,%f,%f",&a, &b); 

    只为这三个值提供了两个参数。

    没有像scanf()中的输入函数一样的question() ,所以如果t不是偶然的’y’或’n’,你会得到一个无限的递归,直到超过堆栈大小…

      以上就是c/c++开发分享C分段故障中的方程求解器相关内容,想了解更多C/C++开发(异常处理)及C/C++游戏开发关注计算机技术网(www.ctvol.com)!)。

      www.ctvol.com true Article c/c++语言开发共享C分段故障中的方程求解器

      本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

      ctvol管理联系方式QQ:251552304

      本文章地址:https://www.ctvol.com/c-cdevelopment/518843.html

      (0)
      上一篇 2020年12月5日 上午12:54
      下一篇 2020年12月5日 上午12:57

      精彩推荐