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 scanf () in c?

818


What is variables in c?

794


What language is lisp written in?

818


Why do we need volatile in c?

921


Some coders debug their programs by placing comment symbols on some codes instead of deleting it. How does this aid in debugging?

848






If null and 0 are equivalent as null pointer constants, which should I use?

796


please explain clearly about execution of c program in detail,in which stage are the printf sacnf getting into exeecutable code

1898


What is LINKED LIST? How can you access the last element in a linked list?

807


What is infinite loop?

823


What does c mean?

757


What is structure padding in c?

811


What is ctrl c called?

771


Why c is a procedural language?

785


Can we declare variables anywhere in c?

748


What functions are used in dynamic memory allocation in c?

768