View Code of Problem 91

#include <stdio.h> 
#include <math.h> 

int isPrime(int a){
	for(int i=2;i<=sqrt(a);i++){
		if(a%i==0){
			return 0;
		}
	}
	return 1;
}

void fun(int x){
	if(isPrime(x)){
		printf("%d",x);
	}else{
		for(int i=2;i<=sqrt(x);i++){
			if(isPrime(i)&&x%i==0){
				printf("%d*",i);
				fun(x/i);
				break;
			} 
		}
	} 
}

int main(){
	int n;
	scanf("%d",&n);
	printf("%d=",n);
	fun(n);
}

Double click to view unformatted code.


Back to problem 91