Write a program to generate prime factors of a given integer?

Answers were Sorted based on User's Feedback



Write a program to generate prime factors of a given integer?..

Answer / ruchi

#include<stdio.h>
#include<conio.h>
int main()
{
int num,i,f=0,k=0,d,m;
printf("\n Enter the number ");
scanf("%d",&num);
m=num;
while(k<=m)
{
k=k+1;
f=0;
d=num%k;
if(d==0)
{
i=2;
while(i<=k-1)
{
if(k%i==0)
{
break;
}
i++;
}
if(i==k)
{
printf("\nPrime Factor %d ",k);
}
}
}
getch();
}

Is This Answer Correct ?    6 Yes 0 No

Write a program to generate prime factors of a given integer?..

Answer / neha

#include<stdio.h>
#include<conio.h>
int main()
{
int num,i=1,j,k;
printf("\n\tEnter the number:");
scanf("%d",&num);
while(i<=num)
{
k=0;
if(num%i==0)
{
j=1;
while(j<=i)
{
if(i%j==0)
k++;
}
j++;
if(k==2)
printf("\n\t%d is a Prime factor:"i);
}
i++;
}
return 0;
}

Is This Answer Correct ?    3 Yes 0 No

Post New Answer

More C Interview Questions

Why is it that not all header files are declared in every C program?

0 Answers  


What is the difference between declaring a variable by constant keyword and #define ing that variable?

1 Answers  


What is the meaning of ?

0 Answers  


what is diffrence between string and character array?

1 Answers  


write a program structure to find average of given number

1 Answers  


write the output of following code .. main() { static int a[]={10,20,30,40,50}; int *ptr=a; static int arr[2][2]={1,2,3,4}; char str[]="ABCD * 4#"; char *s=str+2; int i,j; for(i=0;i<5,i++) printf("%d",*ptr++); for(i=0;i<2;i++) for(j=0;j<2;j++) printf("%d\n",*(*(n+i)+j)); printf("%c\n%c\n%c\n",*(str+2),*s++,*--s); }

1 Answers  


Explain what is the difference between a free-standing and a hosted environment?

0 Answers  


Why C language is a procedural language?

0 Answers   Ericsson,


Are c and c++ the same?

0 Answers  


What is sparse file?

1 Answers  


What is a example of a variable?

0 Answers  


What is function in c with example?

0 Answers  


Categories