Close
Close

Suggestion for C

   Magic105

Hello, I came up with easy solution in C, loop and loop, level 3, 5th. If you find it easier, then replace the exesting one. :) My solution has one less integer and easier to understand.

#include <stdio.h>
int main()
{
    int num,i,j;
    printf("enter a number : ");
    scanf("%d",&num);

    for(i=2;i<num;i++)
    {
       if(num%i==0)//to check it is factor or not
       {            
           for(j=2;(j<i)&&(i%j!=0);j++)    //to check factor is prime or not
            {
                if(j==i-1)
                {
                    printf("%d ",i);
                }
            }

       }
    }
    return 0;
}

You may further explain code with comments but i dont think there is need. Thanks.


Answers

Ask Yours
Post Yours
Write your answer