I'm studying algorithms and would love to learn. My problem is this, I can't output a number "600851475143" using the integer data type in C. So I switched to doubles. However the output is "0.0000". Can someone kindly tell me what I'm doing wrong? I simply want to scan and print any number in the double data type then I'm going to focus on getting the highest prime factor :)
#include <stdio.h>
#include <math.h>
int main()
{
double number;
double div = 2;
double highest = 2;
printf("Please input a number: ");
scanf("%lf", &number);
printf("\n You entered: %lf", &number);
while(number!=0){
if(fmod(number,div) != 0){div = div + 1;}
else{
number = number / div;
printf("\n %lf", div);
if(highest < div){highest = div;}
if(number == 1){break;}
}
}
printf("\n The highest number is %lf", highest);
return 0;}
What I did:
Searched for "scan double in c" in google, learned the "%lf" is the right way to go, but the program doesn't show anything.
I checked out various questions in Stackoverflow like:
Why does scanf need lf for doubles
Reading in double values with scanf in c
Difference between float and double
Read and Write within a file in C (double it)
Reading and writing double precision from/to files
Reading in double values with scanf in c
- Other sites I searched:
http://www.technoburst.net/2011/07/reading-double-in-c-using-scanf.html
Thank you for enlightening me with your knowledge.