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 pointers? What are stacks and queues?
What do you mean by a local block?
Hi can anyone tell what is a start up code?
Why do we use c for the speed of light?
Write a program to print all permutations of a given string.
What is the sizeof () a pointer?
What is size of union in c?
Write a program to implement queue.
What are global variables?
What is dangling pointer in c?
Difference between Function to pointer and pointer to function
What is the use of extern in c?
What is the argument of a function in c?
What are near, far and huge pointers?
What is difference between function overloading and operator overloading?