Wednesday, 7 August 2013

Chapter 5 solutions Problem[D][e]

Question-A positive integer is entered through the keyboard. Write a 
function to obtain the prime factors of this number.
Solution-
good question.

#include<stdio.h>
int main()
{
int n;
printf("Enter any positive integer\n");
scanf("%d",&n);
prime(n);
return 0;
}
prime(int n)
{
int i;
for(i=2;i<=n;i++)
{
while(n%i==0)
{
printf("%d ",i);
n=n/i;
}
}
}

No comments:

Post a Comment