Thread: looking for some maths examples in c ?

  1. #16
    Registered User Euclid365BCE's Avatar
    Join Date
    Jul 2015
    Location
    USA
    Posts
    33
    The general rule is to have a reasonable consistency, i.e., to use a consistent indent style with a consistent number of spaces or a single tab per indent level. There are a few common indentation styles: Wikipedia article on indent styles. The first two in the table shown in the article are the most common; I suggest that you pick one of the two.
    Thank you for your comments. I reviewed the Wiki, and will adopt Allman style.

  2. #17
    Registered User
    Join Date
    Oct 2015
    Posts
    39
    can i get a good working example of a c program solving quadratic equation ?

    every example i try is ending up in some errors ...

  3. #18
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Post your latest effort.

    Sooner or later, you need to develop the skill to write and debug your own code.

    You don't become a great cook by simply visiting restaurants to look at the menu.
    It involves lots of hard work, many failures, and occasional accidents with sharp knives, and maybe the odd fire.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #19
    Registered User
    Join Date
    Oct 2015
    Posts
    39
    thanks for that ...

    i have already tried atleast 12 examples from different places ... everything is giving me errors in my favorite online compiler ... i like that compiler , which is why i keep using it ... i want to see a quadratic equation program in c , succesfully working in that compiler ...

    let me see if i can find a proper example working in that compiler ...

  5. #20
    Registered User
    Join Date
    Oct 2015
    Posts
    39
    i finally found a proper working example ...

    Code:
            #include<stdio.h>
            #include<math.h>
             
            int main(){
              float a,b,c;
              float d,root1,root2;  
             
             
              printf("Enter a, b and c of quadratic equation: ");
              scanf("%f%f%f",&a,&b,&c);
               
              d = b * b - 4 * a * c;
              
              if(d < 0){
                printf("Roots are complex number.\n");
             
                printf("Roots of quadratic equation are: ");
                printf("%.3f%+.3fi",-b/(2*a),sqrt(-d)/(2*a));
                printf(", %.3f%+.3fi",-b/(2*a),-sqrt(-d)/(2*a));
              
                return 0; 
              }
              else if(d==0){
               printf("Both roots are equal.\n");
             
               root1 = -b /(2* a);
               printf("Root of quadratic equation is: %.3f ",root1);
             
               return 0;
              }
              else{
               printf("Roots are real numbers.\n");
              
               root1 = ( -b + sqrt(d)) / (2* a);
               root2 = ( -b - sqrt(d)) / (2* a);
               printf("Roots of quadratic equation are: %.3f , %.3f",root1,root2);
              }
             
              return 0;
            }

    $ cc main.c -lm
    $ a.out
    looking for some maths examples in c ?-b9d2ea-jpg

  6. #21
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    So how much did you learn about programming?

    Congratulations, you managed to use google and copy/paste - what's your next trick?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling some maths examples
    By hamsteroid in forum C Programming
    Replies: 4
    Last Post: 03-29-2007, 02:30 PM
  2. Maths Help
    By bumfluff in forum A Brief History of Cprogramming.com
    Replies: 10
    Last Post: 01-16-2007, 10:53 AM
  3. Help with maths
    By Coritani in forum C++ Programming
    Replies: 11
    Last Post: 11-14-2006, 09:36 AM
  4. maths???
    By nerdyneo in forum C++ Programming
    Replies: 4
    Last Post: 11-09-2003, 01:04 PM
  5. More Maths :(
    By (TNT) in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 01-20-2002, 10:39 AM