Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.92 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int jePrvoc(int y);
  4.  
  5.  
  6. int main()
  7. {
  8.     int x, y, i, j, k, xIndex, *xDelitele;
  9.     printf("Zadej cislo: ");
  10.     scanf("%d", &x);
  11.     xDelitele=NULL;
  12.     xDelitele=(int *)malloc(sizeof(int)*x);
  13.     xIndex = 0;
  14.     for(i=1; i<=x; i++)
  15.     {
  16.         if (x%i==0)
  17.         {
  18.               xDelitele[xIndex] = i;
  19.               xIndex++;
  20.         }
  21.     }
  22.     printf("Pocet delitelu: %d\n", xIndex);
  23.     printf("Delitele: ");
  24.     for(j=0;j<xIndex;j++)
  25.     {
  26.         printf("%d   ", xDelitele[j]);
  27.     }
  28.     printf("\nPrvociselny delitele: ");
  29.     for(k=1;k<xIndex;k++);
  30.     {
  31.         y=xDelitele[k];
  32.         if(jePrvoc(y)==1)
  33.         {
  34.             printf("%d   ", y);
  35.         }
  36.     }
  37.     printf("\n\n");
  38.     free(xDelitele);
  39.     return 0;
  40. }
  41.  
  42. int jePrvoc(int y)
  43. {
  44.     int l;
  45.     for(l=2;l<y;l++)
  46.     {
  47.         if(y%l==0)
  48.         {
  49.             return 2;
  50.         }
  51.     }
  52.     return 1;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement