Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

wrong output to find prime factor of number

$
0
0
what's wrong with this code .
here v= any input value.
if i input 24 as 'v' then i should get 2,2,3,2 as output, but i am getting 2,3,4 as output.
both above are factors of 24 but the one i am getting is not prime factors.

void factor (int v)
      {
      int i;
      for (i=2;i<=v;i++)
      {
          if (v%i==0)
          {
                   printf("\n%d",i);
                   v=v/i;
                   i=2;
          }
      }


Posted Image

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>