Q1 Write a C program where a positive integer is entered thr
Q.1 Write a C program where a positive integer is entered through the keyboard, the program then obtains the prime factors of the number.
Please use // comments so I can follow and understand. Thank you!
Solution
#include<stdio.h>
//main method where calculation is done for prime factors
#include<conio.h>
int main()
{
int num,a=1,b,c;
printf(\"\ Enter a number for which you want prime numbers:\");
scanf(\"%d\",&num);
//the following condition is applied as a number is divisible only till half of its value
while(a<=num/2){
c=0;
//if it is a fator then check if the number is prime or not
if(num%a==0){
b=1;
while(b<=a){
if(a%b==0)
c++;
b++;
}
if(c==2)
printf(\"\ %d is a prime factor of %d\",a,num);
}
a++;
}
getch();
return 0;
}
