Is Integer Factorization Harder Than RSA Factorization?

What is wrong with my c program? prime factorization?

  • my program works well but the only problem is in never outputs hte number 2. when i enter the integer 18 its supposed to spit out the prime factorization which is 2 3 3 but it gives me 3 3. whats wrong... #include<stdio.h> int main() { while(3){ printf("\nEnter an integer: "); int n, x, y, z, k; k = 2; x = 2; while(2){ scanf("%d", &n); if (n <= 1) return (0); if (n > 1) break; } printf("The prime factorization of %d is ",n); while(1){ if (n % k == 0) (n = (n/k)); if (n % k != 0) (k = k + 1); if(k > n) break; if (n % k == 0) printf("%d ",k); } } printf("\n"); return 0; }

  • Answer:

    Try this though it is crude #include<stdio.h> #include<stdlib.h> int main() { int i,n,rn,r=1,j,k; printf("enter an integer\n"); scanf("%d", &n); rn=n; for(j=2;(r!=rn&&n>1)&&j<n;j++) { for(k=2;k<j;k++) { if(j%k==0)break; } if(j==k){ while(n%j==0){ printf("%d ", j); r=r*j; n=n/j; } } } system("PAUSE"); return 0; }

Nana at Yahoo! Answers Visit the source

Was this solution helpful to you?

Other answers

my program works well but the only problem is in never outputs hte number 2. when i enter the integer 18 its supposed to spit out the prime factorization which is 2 3 3 but it gives me 3 3. whats wrong... #include<stdio.h> int main() { while(3){ printf("\nEnter an integer: "); int n, x, y, z, k; k = 2; x = 2; while(2){ scanf("%d", &n); if (n <= 1) return (0); if (n > 1) break; } printf("The prime factorization of %d is ",n); while(1){ if (n % k == 0) (n = (n/k)); if (n % k != 0) (k = k + 1); if(k > n) break; if (n % k == 0) printf("%d ",k); } } printf("\n"); return 0; }

Jahangir

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.