write a progam to display the factors of a given number and
disply how many prime numbers are there?

Answer Posted / sreejesh1987

//This code displays prime factors only

#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,n,x,flag=0,d,count=0;
clrscr();
printf("\tPRIME CHECK\n");
printf("Enter a no:");
scanf("%d",&n);

for(j=2;j<n,n%j!=0;j++)
if(n-1==j)
{
printf("\n\t%d is a prime",n);

flag=1;
}

if(!flag)
{
printf("\nNumber %d is not a prime",n);
printf("\nIts factors are:\n\t");

x=2;
while(n!=1)
{

while(n%x==0)
{
n=n/x;
printf("%d ",x);
count++;
}
x++;
}
printf("\nNumber of factors:%d",count);
}
getch();
}

Is This Answer Correct ?    3 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are pointers? What are stacks and queues?

589


What do you mean by a local block?

639


Hi can anyone tell what is a start up code?

1630


Why do we use c for the speed of light?

616


Write a program to print all permutations of a given string.

654






What is the sizeof () a pointer?

561


What is size of union in c?

589


Write a program to implement queue.

674


What are global variables?

660


What is dangling pointer in c?

633


Difference between Function to pointer and pointer to function

646


What is the use of extern in c?

657


What is the argument of a function in c?

585


What are near, far and huge pointers?

656


What is difference between function overloading and operator overloading?

666