Home › Forums › C Programming › help

- This topic has 1 reply, 2 voices, and was last updated 13 years, 4 months ago by Humayan.

- AuthorPosts
- March 17, 2008 at 11:33 am #2078abhishek3013Participant1234567891011121314151617181920#include<stdio.h><br />int main()<br />{<br />int num = 0;<br />int divisor = 0;<br />int remain = 0;<br />int quotient = 1;<br /><br />printf("Enter a numbern");<br />scanf("%d", &num);<br /><br />printf("Enter a divisor to your number"n);<br />scanf("%d", &divisor);<br /><br />quotient = num/divisor;<br />remain = num % divisor;<br /><br />printf("Quotient is: %dn", quotient);<br />printf("Remainder is: %dn", remain);<br />}

how do i make my program take very large positive numbers without using double precision integer type. for instance:

the user should be able to enter a number like:

5245456638463644648646486464348443466648436446

and get something like:

4243545636758689184912673254783849162783326564 as its quotient and 76586798707897 as its remiander.

i’ll also like to know if its never possible to get that using just “int type”. thanx to all. - March 17, 2008 at 2:34 pm #3359HumayanParticipant
Usually what is done in this case is one is required to write a large number module for your program. A array of the smallest integer type on your machine is usually used ( a short type or something like that ). You will usually use an array like:

short largeNumber [ NUMBER_OF_DIGITS ];

and then you will represent large numbers like:

12345….

largeNumber [ 0 ] = 1largeNumber [ 1 ] = 2

largeNumber [ 2 ] = 3

largeNumber [ 3 ] = 4

largeNumber [ 4 ] = 5

……..

then you write functions to read , write and do mathematical computations on the arrays like:

123456789101112int * num;<br />int * num2;<br />int * sum;<br /><br />initialize ( num , size ); //allocate memory<br />initialize ( num2 , size ); //allocate memory<br /><br />sum = add ( num , num2 ); //sum 2 large numbers<br /><br />printf ( "the sum is n" );<br />printLargeNumber ( sum ); //output sum<br />

- AuthorPosts

- The forum ‘C Programming’ is closed to new topics and replies.