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 the advantage of c?
Array is an lvalue or not?
Explain which of the following operators is incorrect and why? ( >=, <=, <>, ==)
How would you obtain the current time and difference between two times?
Is c easy to learn?
What are dangling pointers? How are dangling pointers different from memory leaks?
A global variable when referred to in another file is declared as this a) local variable b) external variable c) constant d) pointers
Is c is a low level language?
How do you write a program which produces its own source code as output?
What is pointers in c?
What is #ifdef ? What is its application?
What are examples of structures?
What is typedef struct in c?
Write a program to reverse a given number in c language?
Why do we need arrays in c?