Write a program which accepts two numbers and generates prime factors for all numbers in that range.

Example:
I/P ::     a=6, b=12

O/P ::

6     2×3
7     7
8     2x2x2
9     3×3
10   2 x 5
11  11
12  2 x 2 x 3

#include<stdio.h>
main()
{
int a,b,i,j,n,true=1;
int mult=1;
int flag=0;
printf("Enter two numbers, the range::");
scanf("%d %d", &a, &b);
for(i=a;i<=b;i++)
{
n=i;
printf("\nPrime factor of %d ::", n);
for(j=2;j<=n;j++)
{
while(((n%j)==0))
{
printf(" %d",j);
mult=mult*j;
if(mult==n)
{ flag=1;
}
if(flag==1) break;
n=n/j;
}
if(flag==1) break;
}

}
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s