Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- typedef struct valosgyokok {
- float x1, x2;
- } Valosgyokok;
- Valosgyokok masodfoku_valosgyokei(int a, int b, int c, int d);
- int main(void){
- int a;
- int b;
- int c;
- Valosgyokok megoldas;
- printf("Adja meg a masodfoku egyenlet konstansait: ");// a, b, c, NEM NULLA
- scanf("%d, %d, %d", &a, &b, &c);
- int d=b*b-4*a*c;
- if (d>=0) {
- megoldas=masodfoku_valosgyokei(a,b,c,d);
- printf("Az egyenlet megoldasa: x1=%.2f, x2=%.2f\n", megoldas.x1, megoldas.x2);
- }
- else
- printf("Az egyenletnek komplex megoldasa van.\n");
- return 0;
- }
- Valosgyokok masodfoku_valosgyokei(int a, int b, int c, int d){
- Valosgyokok eredmeny;
- if (d==0)
- eredmeny.x1=eredmeny.x2 = -b/(float)(2*a);
- else {
- eredmeny.x1 = -b+sqrt(d)/(2*a);
- eredmeny.x2 = -b-sqrt(d)/(2*a);
- }
- return eredmeny;
- }
Advertisement
Add Comment
Please, Sign In to add comment