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
How many types of errors are there in c language? Explain
Do you know what are the properties of union in c?
What are the data types present in c?
How can you convert integers to binary or hexadecimal?
What is the difference between constant pointer and constant variable?
What is sorting in c plus plus?
What is scope rule in c?
Explain what is meant by high-order and low-order bytes?
we need to calculating INCOME TAX for the person. The INCOME TAX is as follows:- First $10000/- of income : 4% tax Next $10000/- of income : 8% tax Next $10000/- of income : 11.5% tax above $10, 00,00/- : 15% tax What is the Solution of this Question ?
Is null a keyword in c?
How can a process change an environment variable in its caller?
What are bitwise shift operators in c programming?
When is a “switch” statement preferable over an “if” statement?
How do I send escape sequences to control a terminal or other device?
What is unary operator?