User Tools

Site Tools


Sidebar

Programming Reference/Librarys

Question & Answer

Q&A is closed







c:stdlib.h:ldiv

ldiv

    #include <stdlib.h>
    ldiv_t ldiv(long int numerator, long int denominator);

calculate the quotient and remainder in integer division (long integer).

ldiv C Sourcecode Example

/* 
 * ldiv c example code
 * http://code-reference.com/c/stdlib.h/ldiv 
 */
#include <stdio.h> /* including standard library */
//#include <windows.h> /* uncomment this for Windows */
 
#include <stdlib.h>
 
int main( void )
{
  long int numerator, denominator;
  printf("please type in (long int) numerator and denominator for ldiv\n");
  printf("(long int) numerator :");
  scanf("%li", &numerator);
 
  printf("(long int) denominator : ");
  scanf("%li", &denominator);
 
  ldiv_t result = ldiv(numerator, denominator);
 
  printf("%li = %li*%li + %li\n",numerator , denominator, result.quot, result.rem);
  return 0;
}

Output

  Output:
  user@host:~$ ./ldiv 
  please type in (long int) numerator and denominator for ldiv
  (long int) numerator :1234567890
  (long int) denominator : 1234
  1234567890 = 1234*1000460 + 250
advertising
c/stdlib.h/ldiv.txt · Last modified: 2013/01/22 22:02 (external edit)

Impressum Datenschutz