Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- #define CRT_SECURE_NO_WARNINGS
- void main()
- {
- int num, a, b, c, choice;
- double d, Root, Root2, X1, X2;
- /*printf("1. 3 digits number organizing.\n");
- printf("2. Linear equation calculator.\n");
- printf("3. Exit.\n");
- scanf_s("%d", &choice);
- switch (choice)
- {
- case 1: printf("Insert a 3 digits number.\n");
- scanf_s("%d", &num);
- a = num / 100; //מאות
- b = num / 10 % 10;//עשרות
- c = num % 10;//יחידות
- printf("Reversed digits: %d%d%d\n", c, b, a);
- if (a > b)
- {
- if (a > c)
- {
- if (c > b)
- printf("Ascending digits: %d%d%d\n", b, c, a);
- else // a>b && b>c
- printf("Ascending digits: %d%d%d\n", c, b, a);
- }
- else // c>a && a>b
- printf("Ascending digits: %d%d%d\n", b, a, c);
- }
- else // b>a
- {
- if (c > b)
- {
- if (b > a)
- printf("Ascending digits: %d%d%d\n", a, b, c);
- else // c>b && a>b
- printf("Ascending digits: %d%d%d\n", b, a, c);
- }
- else //b>c && b>a
- if (a > c)
- printf("Ascending digits: %d%d%d\n", c, a, b);
- else // b>c && c>a
- printf("Ascending digits: %d%d%d\n", a, c, b);
- }
- break;
- case 2: printf("Insert the coefficients of a linear equation.\n");*/
- scanf_s("%d%d%d", &a, &b, &c);
- d = (double)(b*b) - (4 * a * c);
- Root =(double) sqrt(d);
- X1 = (double)((-b) + Root) / (2 * a);
- X2 = (double)((-b) - Root) / (2 * a);
- Root2 = (double)sqrt((-c / a));
- //(sqrt((b * b) - (4 * a*c))) / (2 * a);
- if ((d < 0) || (a == 0))
- {
- if ((b == 0) && (a == 0))
- printf("X has no solution.\n");
- else
- {
- if (a == 0)
- printf("X = %.1lf\n",(double)((-c) / b));
- else
- if (d == 0)
- printf("X= %.1lf\n", Root2);
- else // d<0
- printf("X has no solution.\n");
- }
- }
- else
- printf("X1= %.1lf X2= %.1lf\n", X1, X2);
- /*break;
- case 3:
- break;
- }*/
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement