We were asked to write a simple program in C language to solve the equation, ax+
ID: 2993495 • Letter: W
Question
We were asked to write a simple program in C language to solve the equation, ax+b=0, for x. If a is 0, print a warning message and exit. This is what I have so far, but it's not compiling. Please correct my program and make comments as to what is wrong.
#include <stdio.h>
int main()
{
float a, b, x;
printf("Enter a and b separated by a comma="); scanf("%f, %f", &a, &b);
if (a==0){ printf("You entered an invalid number. "); return 0;}
else x=-b/a;
printf("x= %f -b/a ", a, b,);
return 0;
}
Explanation / Answer
#include <stdio.h>
int main()
{
float a, b, x;
printf("Enter a and b separated by a comma ");
scanf("%f, %f", &a, &b);
if (a==0){ printf("You entered an invalid number. "); return 0;}
else x=-b/a;
printf("x= %f",x);
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.