Home Forums C Programming To Find the Prime Factors of a Number

Viewing 1 reply thread
  • Author
    Posts
    • #2257
      Anonymous
      Inactive


      #include
      #include
      #include
      #include
      #include

      int main()
      {
      int x,div=2;


      int i=0,j=0;
      clrscr();
      printf("Enter Number X : ");
      scanf("%d",&x);
      int num=x;
      int *prime=(int *) malloc(x*sizeof(int));
      printf("n Allocated n");
      getch();
      if (x==1 || x==0)
      { printf(" Number %d have no prime Factors",x);
      *prime=0;
      }
      else
      { while(x>1)
      { if ((x%div)==0)
      { *(prime+i)=div;x=x/div;i++;printf("n Prime Factorn");

      }
      else
      { div++; }

      }


      }

      printf("n The Prime Factors for Number %d are :n",num);

      for(j=0;j
      { printf (" %d ",*(prime+j)); }

      getch();
      return(0);
      }

    • #3662
      Anonymous
      Inactive

      Please visit the Site http://contest.collectiva.in/Contest/ContestTraining.aspx To learn Fundamentals of C Programming in Tamil. It is very useful for the Beginners.

Viewing 1 reply thread
  • The forum ‘C Programming’ is closed to new topics and replies.