Categories
Mastering Development

(C Language) prime factorization. How to make output 2 2 2 3 7 7 become 2^3 * 3^1 * 7^2?

#include <stdio.h>

int main() {

    int n,i;
    
    scanf("%d",&n);
    
    for(i=2;i>=n/2;i++)
    {
        
        while(n%i==0)
        {
            printf("%d  ",i);
            n=n/i;
        }
        
    }
    return 0;
}

(C Language) prime factorization. How to make output 2 2 2 3 7 7 become 2^3 * 3^1 * 7^2 ?

Leave a Reply

Your email address will not be published. Required fields are marked *