Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*Schrijf een programma, ontwerp en code, waarmee de wortels van een willekeurig
- tweede-graad-vergelijking te vinden zijn. Zoals bekend is uit de analyse, zijn deze
- wortels te berekenen met de ABC – formule:
- (𝑥1,2 = ) −𝑏∓√𝑏^2−4𝑎𝑐 / 2𝑎
- Indien de discriminant (het deel onder de wortel) negatief is, zijn er geen reële
- oplossingen maar zijn er twee imaginaire oplossingen. Indien de discriminant nul is,
- is er één oplossing. En als de discriminant positief is, zijn er twee reële oplossingen.
- In het eerste geval wordt de mededeling “discriminant is negatief” afgedrukt. Voor
- de andere gevallen worden de oplossingen afgedrukt.
- Het programma moet tenminste de volgende functies bevatten:
- void abc(double a, double b, double c)
- double discriminant(double a, double b, double c)*/
- ------------------------------------------------------Written in dutch-----------------------------------------------------------------
- #include <stdio.h>
- #include <math.h>
- double discriminant(double a, double b, double c)
- {
- return (pow(b, 2) - 4 * a * c);
- }
- void abc(double a, double b, double c)
- {
- if(discriminant(a, b, c) < 0){
- printf("De vergelijking %.4lfx^2 + %.4lfx^2 + %.4lfx^2 heeft geen reele oplossingen.\n", a, b, c);
- return;
- }
- double formula1 = (-b + sqrt(discriminant(a, b, c))) / (2 * a);
- if(discriminant(a, b, c) == 0){
- printf("De oplossing van %.4lfx^2 + %.4lfx^2 + %.4lfx^2 is:\nx = %.4lf\n", a, b, c, formula1);
- return;
- }
- double formula2 = (-b - sqrt(discriminant(a, b, c))) / (2 * a);
- if(discriminant(a, b, c) > 0){
- printf("De oplossingen van %.4lfx^2 + %.4lfx^2 + %.4lfx^2 is:\n(x1 = %.4lf), (x2 = %.4lf)\n", a, b, c, formula1, formula2);
- }
- }
- int main() {
- int testcases;
- scanf("%d",&testcases);
- for(int i=0; i < testcases; i++ ){
- double a, b, c;// doubling it
- scanf("%lf%lf%lf", &a, &b, &c);//has double value/ user input
- abc(a, b, c);// send user input to abc
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement