Algorithms_in_C  1.0.0
Set of algorithms implemented in C.
sol2.c File Reference

Problem 3 solution More...

#include <stdio.h>
Include dependency graph for sol2.c:

Functions

int main ()
 

Detailed Description

Problem 3 solution

Problem:

The prime factors of 13195 are 5,7,13 and 29. What is the largest prime factor of a given number N? e.g. for 10, largest prime factor = 5. For 17, largest prime factor = 17.

Function Documentation

◆ main()

int main ( )

Main function

15 {
16  int n = 0;
17  scanf("%d", &n);
18  int prime = 1;
19  int i = 2;
20  while (i * i <= n)
21  {
22  while (n % i == 0)
23  {
24  prime = i;
25  n /= i;
26  }
27  i += 1;
28  }
29  if (n > 1)
30  prime = n;
31  printf("%d\n", prime);
32  return 0;
33 }