To solve a simple equation in C

Wednesday, June 16, 2010

Whether you are in middle school, high school or even college, you will quickly learn that knowing how to solving equations is essential to any mathematics class. The majority of applications in mathematics will end up in an equation, and you will have to be able to solve that equation in order to answer the original problem. By going over the steps to solving two different linear equations, you will get a better understanding of how they are solved. The two different equations will be in forms ax + b = c and ax - b = c, where a, b and c will be replaced by numeric values and x represents the variable you will be solving for. For the purpose of solve this procedure, the following source code examples will be used: ax+b=0 .

// C08_Ex 3: To solve a simple equation: ax + b = 0

#include <stdio.h>
#include <conio.h>

void main()
{
    int a, b;
    printf("Ipnput a, b: ");
    scanf("%d%d", &a, &b);
  
    if (a == 0)
    {
        if (b == 0)
            printf("=> Equation has multitudinous root\n");
        else
            printf("=> Equation has not root\n");
    }
    else
        printf("=> Equation only has a root: x = %.2f\n", (float)-b/a);
}

0 Comments:

Post a Comment

 
 
 
 
Copyright © 2010 C Source Code - C++ Source Code. All Rights Reserved. Using Xclear Theme | Bloggerized by Themescook Developed by Helios | Powered by Blogger