#include <stdio.h>
int main()
{
printf("choose number");
c();
}
c()
{
printf("1. ax+b=0
");
printf("2. ax+by+c=0
dx+ey+f=0
");
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.
");
c();
}
formula1()
{
printf("ax+b=0
");
printf("Enter your values for a and b respectively, seperated by commas
");
float a, b, x;
scanf("%f,%f,%f", &a, &b);
x = -b / a;
printf("x=-b/a
");
printf("=>x=%f", x);
question();
}
formula2()
{
printf("ax+by+c=0
dx+ey+f=0
");
printf(
"Enter your values for a, b, c, d ,e and f respectively, seperated by commas
");
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("
");
printf("=>y=%f", y);
question();
}
question()
{
char t;
printf("
another equation?
y/n?
");
if (t == 'y')
{
printf("
");
c();
}
else if (t != 'n')
question();
}
I have this code, which in short solves 3 equations.
When you select any choice it seems to run the question method multiple times then quits due to a segmentation fault: 11
Could someone please point out where I am going wrong. Any other help with my code would be greatly appreciated
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…