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 are enumerations in C
Which is better pointer or array?
What is the difference between the = symbol and == symbol?
how can I convert a string to a number?
List at least 10 sorting methods indicating their average case complexity, worst case complexity and best case complexity.
What is the mean of function?
What is a pointer on a pointer in c programming language?
What is function definition in c?
How can I remove the trailing spaces from a string?
Explain what is wrong with this program statement? Void = 10;
How can I display a percentage-done indication that updates itself in place, or show one of those twirling baton progress indicators?
What are the different types of data structures in c?
What are runtime error?
Calculate 1*2*3*____*n using recursive function??
What is extern variable in c with example?