Advertisement
Dr4noel

Program F.A.I.

Jan 7th, 2018
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.38 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <conio.h>
  3. #include <math.h>
  4.  
  5. void main() {
  6.     int gp, numarCoeficienti, i, coeficienti[100], divizori[100], k = 0, val = 0, l = 0;
  7.     int sumaDP = 0, sumaDN = 0;
  8.  
  9.     printf("Introduceti gradul polinoamelor: \n");
  10.     scanf_s("%d", &gp);
  11.  
  12.     while (gp < 1) {
  13.         printf("Reintroduceti gradul: ");
  14.         scanf_s("%d", &gp);
  15.     }
  16.  
  17.     printf("Scrieti coeficienti polinomului: \n");
  18.     for (i = 0; i <= gp; i++) {
  19.         printf("\nX^%d = ", i);
  20.         scanf_s("%d", &coeficienti[i]);
  21.     }
  22.  
  23.     printf("Polinomul este: \n");
  24.  
  25.  
  26.     for (i = gp; i >= 0; i--) {
  27.         if (coeficienti[i] != 0) {
  28.             printf("%+dx^%d ", coeficienti[i], i);
  29.         }
  30.     }
  31.  
  32.     if (coeficienti[0] < 0) {
  33.         for (i = 1; i <= (-1 * coeficienti[0]); i++) {
  34.             if (coeficienti[0] % i == 0) {
  35.                 divizori[k] = i;
  36.                 k++;
  37.                 val++;
  38.             }
  39.         }
  40.     }
  41.     else {
  42.         for (i = 1; i <= coeficienti[0]; i++) {
  43.             if (coeficienti[0] % i == 0) {
  44.                 divizori[k] = i;
  45.                 k++;
  46.                 val++;
  47.             }
  48.         }
  49.  
  50.     }
  51.    
  52.     for (k = 0; k < val; k++) {
  53.         sumaDP = 0, sumaDN = 0;
  54.         for (i = 0; i <= gp; i++) {
  55.            
  56.             sumaDP = sumaDP + (coeficienti[i] * (pow(divizori[k], i)));
  57.  
  58.             sumaDN = sumaDN + (coeficienti[i] * (pow(-divizori[k], i)));
  59.  
  60.         }
  61.         if ((sumaDP == 0) || (sumaDN == 0)) {
  62.             l++;
  63.             break;
  64.         }
  65.     }
  66.     if (l > 0){
  67.         printf("\nPolinomul este reductibil!");
  68.     }
  69.     else {
  70.         printf("\nPolinomul este ireductibil!");
  71.     }
  72.  
  73.  
  74.     _getch();
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement