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 can’t we compare structures?

0 Answers  


Explain what are reserved words?

0 Answers  


Why we use stdio h in c?

0 Answers  


What does c in a circle mean?

0 Answers  


What is huge pointer in c?

0 Answers  






How pointer is different from array?

0 Answers  


#include<stdio.h> main() {int i=1;j=1; for(;;) {if(i>5) break; else j+=1; printf("\n%d",j) i+=j; } }

7 Answers   HCL,


swap 2 numbers without using third variable?

0 Answers   IBS,


which do you prefer C or Pascal?

1 Answers  


main() { int x=20,y=35; x = y++ + x++; y = ++y + ++x; printf("%d %d\n",x,y); } what is the output?

10 Answers   Ramco,


Can you please compare array with pointer?

0 Answers  


write the program for prime numbers?

73 Answers   Accenture, Aptech, Infosys, TCS,


Categories