Write a C program to input a number from user and find Prime factors of the given number using loop. C program to list all prime factors of a given number. Logic to find prime factors of a number in C programming. Example Input Input any number: 10 Output Prime factors of 10: 2, 5 Required knowledge Basic C programming , If statement , For loop , Nested loop What is Prime factor? Factors of a number that are prime numbers are called as Prime factors of that number. For example: 2 and 5 are the prime factors of 10. Logic to check prime factors of a number Step by step descriptive logic to find prime factors. Input a number from user. Store it in some variable say num . Run a loop from 2 to num/2 , increment 1 in each iteration. The loop structure should look like for(i=2; i<=num/2; i++) . You may think why loop from 2 to num/2 ? Because prime number starts from 2 and any factor of a number n is ...
sahilsengra.blogspot.com
Comments
Post a Comment