LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Using gmc.h library (https://www.linuxquestions.org/questions/programming-9/using-gmc-h-library-4175549984/)

Davidbow23 08-05-2015 08:31 PM

Using gmc.h library
 
Here is a little C program I have written to factorise a number - I wish to input larger numbers than long long integers can handle - so I wish to use gmc.h library.
I am finding his a little confusing so If anyone would convert the program below, I would be thankful.

/*
Factorisation program based upon an ealier version written in Pascal. Finds and lists all the
factors in a given integer. Tests if input_number MODULUS testnumber is zero. If so, the test number
and (input number DIVIDED by the test number) is printed and the total number off counted.
There is only the need to for the test number to range from unity to the square root of the input
number. The square root is found is reached when the (input number DIVIDED by the test number)
is <= test number. No floating point routines are used.
*/

#include <stdio.h>
#include <stdlib.h>

int main()
{
unsigned long long int input_num, buff;
unsigned long int test_num =1, factor_cnt = 0;
int column_cnt = 0;

printf ("Enter number to be factorised: ");
scanf ( "%Ld", &input_num);
printf ( "The factors of %Ld are listed below \n\n", input_num );
while (test_num <= (buff = input_num / test_num))
// true while test_num <= SQRT of input_num
{ if ( input_num % test_num == 0)
{ printf ( "%-20Ld", buff);
factor_cnt ++;
if (buff != test_num)
// always true if input_num is NOT a perfect square
{ printf ("%-20ld",test_num);
factor_cnt ++;
}
column_cnt ++;
if ( column_cnt == 2)
{ printf ( "\n" );
column_cnt = 0;
}
}
test_num ++ ;
}

printf (" \nThere are %-10lu different factors in %-20Lu\n", factor_cnt,
input_num);
return (1);

John VV 08-06-2015 01:05 PM

please post a link to this "gmc.h"

is it GNU Midnight Commander ( GMC)

also please USE the code tags for code
PHP Code:

 [codeplace the code here [/code

Code:


#include <stdio.h>
#include <stdlib.h>

int main()
{
unsigned long long int input_num, buff;
unsigned long int test_num =1, factor_cnt = 0;
int column_cnt = 0;


michaelk 08-06-2015 01:31 PM

I think the OP is actually asking about the gmp library. https://gmplib.org/


All times are GMT -5. The time now is 04:13 AM.