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 is a global variable in c?

596


What is a far pointer in c?

603


Can you assign a different address to an array tag?

704


What will be your course of action for a push operation?

669


Can a function argument have default value?

676






How does free() know explain how much memory to release?

623


Explain what is the purpose of "extern" keyword in a function declaration?

626


Why is python slower than c?

611


Can you please compare array with pointer?

621


#define MAX(x,y) (x) >(y)?(x):(y) main() { inti=10,j=5,k=0; k= MAX(i++,++j); printf("%d..%d..%d",i,j,k); }

786


What are the benefits of c language?

651


What is c basic?

606


What’s a signal? Explain what do I use signals for?

615


Explain about C function prototype?

613


can any one please explain, how can i access hard disk(physical address)? it is possible by the use of far,near or huge pointer? if yes then please explain......

1415