Result for number aboove its range
Hey can anyone tell me, that if i want to make a program which test whether a no is prime or nt for all integers and also for nos above the range of integer. Is there any way. Do i need to set my own range. pls tell me a way.

Re: Result for number aboove its range
There are no (finite) numbers beyond the range of integer. Do you mean the int type? If so you may be able to extend the range by using long instead of int. Check your compiler documentation for how large the different integer types are; the standard only mandates that short <= int <= long, so all integer types could be 32bit.
If no built in types fit the range you want to test then you'll have to define your own type and encode the operations you want to use. This isn't as difficult as it sounds; there's already an example of how we normally do that in this reply, i.e. the number 32  no single digit has a value greater than 9, so we use multiple digits to represent numbers larger than 9. So you can use multiple ints to represent numbers larger than 2^(8*sizeof int), for example int bignum[4] will represent a number up to 2^(4*8*sizeof int). Then you will need to write code to add these, because the built in operators only know about built in types. Again this is fairly easy; just remember how you did it on paper then write code to do that, for example: 1234 5678+ ==== 4+8=12, so write 2 below 4 and 8 and carry the 1. 3+7=10, add the carry=11, write 1, carry 1. 2+6=8, add carry=9, write 9. 1+5=6. So in code you might have something like (simplified): Code:
int bignum1[4]={1,2,3,4}; 
Re: Result for number aboove its range
What i did is I create a func atoi1 as i want in long long
so i wrote unsigned long long atoi1(char s[]) { unsigned long long m=0; int i; for(i=0;s[i]>='0' && s[i]<='9';++i) m=10*m+(s[i]'0'); return m; } in main i create an array which takes the no string from user and with the help of this func it converts it into long long again it is giving negative result on exceeding the value from 32767 ie 16 bit 
Re: Result for number aboove its range
How are you displaying the return value?
I tried the above code and it worked fine with 1048576, using Visual Studio 2005. 
Re: Result for number aboove its range
i did in TC. and i wrote printf("%d",m);
oh i should try %ld, is this the prob. let me check it on visual studio 
All times are GMT +5.5. The time now is 14:58. 