The following code shows how to Display All Prime Factors of a Number in C.
// Find Prime Factors of a Number
#include <stdio.h>
int main()
{
int mynumber, i, j, prime=1, factor;
printf("Enter a number: ");
scanf("%d", &mynumber);
printf("Prime Factors of the number %d are...\n", mynumber);
for(i=2;i<=mynumber;i++){
if(mynumber%i==0)
{
factor=i;
for(j=2;j<=factor/2;j++)
{
if(factor%j==0)
{
prime=0;
break;
}
}
if(prime)
{
printf("%d ", factor);
}
prime=1;
}
}
return 0;
}
Output
Enter a number: 329
Prime Factors of the number 329 are…
7 47
Further Reading
50+ C Programming Interview Questions and Answers
C Program to Find Factorial of a Number
- AI
- Android
- Angular
- ASP.NET
- Augmented Reality
- AWS
- Bioinformatics
- Biometrics
- Blockchain
- Bootstrap
- C
- C#
- C++
- Cloud Computing
- Competitions
- Courses
- CSS
- Cyber Security
- Data Science
- Data Structures and Algorithms
- Datafication
- Deep Learning
- DevOps
- Digital Forensic
- Digital Trust
- Digital Twins
- Django
- Docker
- Dot Net Framework
- Drones
- Elasticsearch
- Extended Reality
- Git
- Go
- HTML
- Image Processing
- IoT
- IT
- Java
- JavaScript
- Kotlin
- Latex
- Machine Learning
- MEAN Stack
- MERN Stack
- Microservices
- MongoDB
- NodeJS
- PHP
- Power Bi
- Projects
- Python
- Quantum Computing
- React
- Robotics
- Rust
- Scratch 3.0
- Shell Script
- Smart City
- Software
- Solidity
- SQL
- SQLite
- Tecgnology
- TypeScript
- VB.NET
- Virtual Reality
- Web Designing
- WebAssembly
- XML