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
What is scanf () in c?
What is variables in c?
What language is lisp written in?
Why do we need volatile in c?
Some coders debug their programs by placing comment symbols on some codes instead of deleting it. How does this aid in debugging?
If null and 0 are equivalent as null pointer constants, which should I use?
please explain clearly about execution of c program in detail,in which stage are the printf sacnf getting into exeecutable code
What is LINKED LIST? How can you access the last element in a linked list?
What is infinite loop?
What does c mean?
What is structure padding in c?
What is ctrl c called?
Why c is a procedural language?
Can we declare variables anywhere in c?
What functions are used in dynamic memory allocation in c?