Thread: Prime Factor

  1. #1
    Registered User
    Join Date
    Jul 2020
    Posts
    6

    Prime Factor

    Code:
    #include <stdio.h>
    
    int main(){
    int i, j, num, num1, isPrime;
    
    scanf("%d %d", &num, &num1);
    
    for(i = 2; i <= (num % num1); i++){
    if((num % num1) % i==0){
    isPrime = 1;
    for(j = 2; j <= i / 2; j++){
    if(i % j == 0){
    isPrime = 0;
    break;
    }
    }
    if(isPrime == 1){
    printf("%d ", i);
    
    }
    }
    }
    return 0;
    }
    Want to ask that is the main prime factor if for example the input 6 12 then the result is 6 but the coding instead has 2 3.


    Input:
    6 12
    Output:
    6


    Enable GingerCannot connect to Ginger Check your internet connection
    or reload the browserDisable in this text fieldEditLog in to edit with GingerLog in to edit with Ginger×
    Attached Images Attached Images Prime Factor-20200729_231901-jpg 

  2. #2
    Registered User
    Join Date
    Jul 2020
    Posts
    6
    Quote Originally Posted by Suntani View Post
    Code:
    #include <stdio.h>
    
    int main(){
    int i, j, num, num1, isPrime;
    
    scanf("%d %d", &num, &num1);
    
    for(i = 2; i <= (num % num1); i++){
    if((num % num1) % i==0){
    isPrime = 1;
    for(j = 2; j <= i / 2; j++){
    if(i % j == 0){
    isPrime = 0;
    break;
    }
    }
    if(isPrime == 1){
    printf("%d ", i);
    
    }
    }
    }
    return 0;
    }
    Want to ask that is the main prime factor if for example the input 6 12 then the result is 6 but the coding instead has 2 3.


    Input:
    6 12
    Output:
    6


    Enable GingerCannot connect to Ginger Check your internet connection
    or reload the browserDisable in this text fieldEditLog in to edit with GingerLog in to edit with Ginger×
    And so if you are looking for prime numbers between the two numbers, what your complaint about 2 * 3 = 6 have to do anything with the question? Why is the title of your question "prime factor" instead of a more appropriate "prime numbers"
    Enable GingerCannot connect to Ginger Check your internet connection
    or reload the browserDisable in this text fieldEditLog in to edit with GingerLog in to edit with Ginger×Enable GingerCannot connect to Ginger Check your internet connection
    or reload the browserDisable in this text fieldEditEdit in GingerEdit in Ginger×

  3. #3
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Suntani: you posted this twice, and it looks like you copied and pasted this from somewhere such that you both asked a question and then appear to address the question. Presently, you're giving me the impression that you're a spam bot hoping to get a couple of posts in before you unleash the spam. Please convince me otherwise by sensibly addressing my question to you:

    Quote Originally Posted by Suntani
    Want to ask that is the main prime factor if for example the input 6 12 then the result is 6 but the coding instead has 2 3.
    Are you aware that 6 cannot be a prime factor because it is not a prime number?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Prime Factor
    By Suntani in forum C Programming
    Replies: 2
    Last Post: 07-29-2020, 10:36 PM
  2. Prime factor
    By alperen1994 in forum C Programming
    Replies: 6
    Last Post: 03-28-2009, 01:31 PM
  3. last prime factor
    By frango9000 in forum C Programming
    Replies: 7
    Last Post: 07-27-2006, 12:42 PM
  4. Prime factor
    By caroundw5h in forum C Programming
    Replies: 6
    Last Post: 01-13-2004, 03:39 PM
  5. Prime Factor Fxn
    By alpha in forum C++ Programming
    Replies: 2
    Last Post: 10-21-2003, 10:44 AM

Tags for this Thread