#include<stdio.h>
int is_prime (int no){
int i=2;
while(i <= no-1){
if(no % i == 0){
return 0;
}
i++;
}
// i know that my number is not composite
return 1;
}
void largest_prime_factor (int no){
int i;
for(;i<=no/2;i--){
if(no%i==0 && is_prime(i)==1){
printf("Largest prime number that divides %d evenly is %d\n", no, i);
}
}
}
int prime_string (int no){
int i;
for(i=2;i<=no-1;i++){
if(is_prime(i)==1 && no%i==0){
//printf("Prime factors = %d * ", i);
return 1;
}
else if(is_prime(no)==1){
return 2;
//printf("%d", no);
}
no=no/i;
}
}
void main()
{
int no,i,mod, num_prime;
char input,answer;
printf("Please enter a positive integer:");
scanf("%d",&no);
scanf("%c", &input);
while (input != 'q') {
num_prime = is_prime(no);
if (num_prime == 0) {
int i;
printf ("COMPOSITE\n");
printf ("Largest number that divides %d evenly is %d\n", no/i, no);
switch(prime_string(no)){
case 1:
printf("Prime factors = %d * ", i);
case 2:
printf("%d", no);
break;
}
printf("Please enter a positive integer (or q to quit): ");
scanf("%d",&no);
scanf("%c", &input);
}
else {
printf ("PRIME\n");
printf("Please enter a positive integer (or q to quit): ");
scanf("%d",&no);
scanf("%c", &input);
}
}
Edited by WingedPanther, 22 February 2009 - 03:41 AM.
add code tags (the # button)


Sign In
Create Account

Back to top










