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

write a prgram of swapping with 2 valiables

6 Answers  


Explain the use of bit fieild.

0 Answers  


How do you search data in a data file using random access method?

0 Answers  


Determine if a number is a power of 2 at O(1).

2 Answers  


Can you please explain the scope of static variables?

0 Answers  






Explain how can you determine the size of an allocated portion of memory?

0 Answers  


How can you convert integers to binary or hexadecimal?

0 Answers  


printf("%d",(printf("Hello")); What it returns?

32 Answers   TCS,


Why can arithmetic operations not be performed on void pointers?

0 Answers  


Write a program that will read the input of any number of digits n in a row of shafh showing the breakdown of the printing and printing figures by the recursive function.

0 Answers  


logic for x=y^n

1 Answers   Delphi,


which is an algorithm for sorting in a growing Lexicographic order

0 Answers  


Categories