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

Which weighs more, a gram of feathers or a gram of gold?

2 Answers  


void main() { int i=5; printf("%d",i++ + ++i); }

21 Answers   ME,


main() { char *p; p="Hello"; printf("%c\n",*&*p); }

2 Answers   ME,


void main() { char far *farther,*farthest; printf("%d..%d",sizeof(farther),sizeof(farthest)); }

3 Answers   ME, pspl,


a character variable can at a time store a) 1 character b) 8 characters c) 254 characters d) none of the above

3 Answers  


How are portions of a program disabled in demo versions?

0 Answers  


6)What would be the output? main() { int u=1,v=3; pf("%d%d",u,v); funct1(&u,&v); pf("%d%d\n",u,v); } void funct1(int *pu, int *pv) { *pu=0; *pv=0; return; } a)1 3 1 3 b)1 3 1 1 c)1 3 0 0 d)1 1 1 1 e) 3 1 3 1

4 Answers  


What is function prototype?

0 Answers  


What is an identifier?

0 Answers  


What is hash table in c?

0 Answers  


write a program that types this pattern: 12345678987654321 12345678 87654321 1234567 7654321 123456 654321 12345 54321 1234 4321 123 321 12 21 1 1

0 Answers  


write a c program to find reminder and quotient if one number is divided by other.to code this program don't use more than 2 variables

2 Answers   TCS,


Categories