answersLogoWhite

0


Best Answer

#include <stdio.h> #include <conio.h> #include <math.h> void main() { float a, b, c; float root1, root2,de,d; printf("enter the values of a, b and c"); scanf("%f%f%f", &a,&b,&c); de=(b*b)-4*(a*c); d=sqrt(de); root1=(-b+d) /(2.0*a); root2=(-b-d) /(2.0*a); printf(" roots of the equation are %f %f", root1,root2); getch(); }

User Avatar

Wiki User

12y ago
This answer is:
User Avatar
More answers
User Avatar

AnswerBot

8mo ago

Here is an example of a C program that calculates the roots of a quadratic equation using two pointer parameters:

#include <stdio.h>
#include <math.h>

void calculateRoots(float a, float b, float c, float* root1, float* root2) {
    float discriminant;

    discriminant = b*b - 4*a*c;

    if(discriminant > 0) {
        *root1 = (-b + sqrt(discriminant)) / (2*a);
        *root2 = (-b - sqrt(discriminant)) / (2*a);
        printf("Roots are real and different.\n");
    } else if(discriminant == 0) {
        *root1 = *root2 = -b / (2*a);
        printf("Roots are real and the same.\n");
    } else {
        printf("Roots are complex and different.\n");
    }
}

int main() {
    float a, b, c, root1, root2;

    printf("Enter coefficients a, b, and c: ");
    scanf("%f %f %f", &a, &b, &c);

    calculateRoots(a, b, c, &root1, &root2);

    printf("Root 1: %.2f\n", root1);
    printf("Root 2: %.2f\n", root2);

    return 0;
}

In this program, the calculateRoots function takes the coefficients a, b, and c of the quadratic equation as well as two pointer parameters root1 and root2 to store the roots. It calculates the roots using the quadratic formula and updates the values pointed to by the pointers. The main function prompts the user to enter the coefficients, calls the calculateRoots function, and then prints the roots.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: C program to calculate the roots of a quadratic equation using two pointer parameters?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering
Related questions

What is parameters in C plus plus?

In C++, parameters are variables declared in the function's declaration and definition that receive values passed in from the function call. They are used to pass values or data into a function to be used within the function's code. Parameters allow functions to be more flexible and reusable by accepting different inputs without needing to modify the function's code.


What is the difference between value type parameters and reference type parameters?

When a variable is passed by value, the function receives a copy of the variable. When a variable is passed by reference, the function receives a reference, or pointer, to the original data.


How do declare function pointer having two integer parameters and returning integer pointers?

// declare a function int* function(int, int); or int* (function)(int, int); // declare a pointer to a function int* (*pointer_to_function)(int, int);


Why you are using VOID in C programming?

You don't use 'VOID', but 'void'. It means different things, such as:- void as function type means no return value- void as function parameter means no parameters- 'void *' as pointer-types means generic pointer


Can you overload object pointers?

Overloading refers to defining multiple functions of the same name with different numbers/types of parameters. So no, you cannot overload a pointer.


What is THIS operator in c?

The this operator is not a c operator. It is a c++ keyword. It is equivalent to an r-value pointer to the current instance of an object. It is useful when resolving between object members and method parameters.


Do functions get called by reference only?

No. Function parameters are passed by value. Always. Even the so called "call by reference" is a value - the value of the pointer or the address of the object - but what is placed in the parameter list is a value.


Difference between pointer to constant and constant pointer?

1. pointer to a constant means you can not change what the pointer points to 2. constant pointer means you can not change the pointer.


What is triple pointer?

Example: int x; -- integer int *px= &amp;x; -- pointer to integer int **ppx= &amp;px; -- pointer to pointer to integer int ***pppx= &amp;ppx; -- pointer to pointer to pointer to integer


What are pointer to pointer?

A pointer only holds an address information (location) in the memory. if a pointer holds points another pointer then it is a pointer to an other pointer. Pointer holds an address in the memory so in that address there is an other location information that shows another location.


Advantages of pointer in c?

pointer in C have following advantages- 1.Pointer is a very useful concept for creating the important C data structures i.e. linked list, stack, queues and trees, which are very powerful in certain situations. 2.Pointers are very useful when we have to reflect more than one variable change in the calling function after call takes place i.e. though we can not return more than one value from a called function but we can always pass references (pointer variables) to the variables in calling function as parameters to the function.So all the manipulation using these pointer variables will be reflected in called funtion. 3.Pointer provides a lower level view of memory, it adds to our understanding of the things going on in your computer memory.


Why do you use a void pointer in a programme?

void is type of pointer that usually means that you can make it point to any data type. When you make a pointer point to somewhere its data type should match with the place where you want it to point. When you dont know the data type where it will point to then you can declare a void pointer and make it point to the data type it want.