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 do you mean by invalid pointer arithmetic?
Why are algorithms important in c program?
Define the scope of static variables.
What are the rules for identifiers in c?
What is getch() function?
Explain Basic concepts of C language?
Explain what is operator promotion?
There is a practice in coding to keep some code blocks in comment symbols than delete it when debugging. How this affect when debugging?
Does c have class?
Explain what is meant by high-order and low-order bytes?
Tell us bitwise shift operators?
Why we use void main in c?
What is structure in c language?
What is a macro in c preprocessor?
What is getche() function?