473,396 Members | 1,995 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

what's this???

Today when I build a program,the compiler tells me there is no
error,but when I run it ,it shows " 1.#INF00000",what's the
meaning??????The program is as follows:
#include<stdio.h>
int main()
{ int x,y;
int w=0;
long double z=0;

for(x=0;x<=10;x++)

{if(x==0)

{w=1;}

else

{for(y=1;y<=x;y++)

{w*=y;} }

z+=(float)1/w;}

printf("%.9Lf",z);
return 0;}
Nov 8 '08 #1
4 2066
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

questions wrote:
Today when I build a program,the compiler tells me there is no
error,but when I run it ,it shows " 1.#INF00000",what's the
meaning??????The program is as follows:
#include<stdio.h>
int main()
{ int x,y;
int w=0;
long double z=0;

for(x=0;x<=10;x++)

{if(x==0)

{w=1;}

else

{for(y=1;y<=x;y++)

{w*=y;} }

z+=(float)1/w;}

printf("%.9Lf",z);
return 0;}
It looks like "int" is too small to fit the value you assign to w. You
should check which type is sufficient (limits.h). According to C++
standard the largest integer type is unsigned long int and the largest
floating point type is long double. In fact, the second one was enough
to made this code working on my implementation.

I'd suggest you to format your code in an easier to read way.

Pawel Dziepak
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org

iEYEARECAAYFAkkVezgACgkQPFW+cUiIHNpFuACdFenI7FQvVz OB5VcK1TWfQIy8
uOsAnAsW8j1HozMc4oaxu5JAk4fkSftA
=pYqQ
-----END PGP SIGNATURE-----
Nov 8 '08 #2
questions wrote:
Today when I build a program,the compiler tells me there is no
error,but when I run it ,it shows " 1.#INF00000",what's the
meaning??????
One question mark is enough. More makes the question just look silly.
The meaning is probably that you are dividing by zero.
The maximum value that w would reach probably a lot bigger than int
can handle on your platform.

Nov 8 '08 #3
#include<stdio.h>
z+=(float)1/w;}
printf("%.9Lf",z);
Should you post to the c.l.c instead of c.l.c++
what's the meaning??????
Looks like w is overflowed. Use long types / float, double / ...
Nov 8 '08 #4
On 11ÔÂ8ÈÕ, ÏÂÎç5ʱ37·Ö, questions <mengqidhu...@yahoo.cnwrote:
Today when I build a program,the compiler tells me there is no
error,but when I run it ,it shows " 1.#INF00000",what's the
meaning??????The program is as follows:
#include<stdio.h>
int main()
{ int x,y;
int w=0;
long double z=0;

for(x=0;x<=10;x++)

{if(x==0)

{w=1;}

else

{for(y=1;y<=x;y++)

{w*=y;} }

z+=(float)1/w;}

printf("%.9Lf",z);

return 0;}
overflow!!!
You can see by this:

#include<stdio.h>
int main()
{
int x,y;
int w=0;
long double z=0;

for(x=0;x<=10;x++)
{
if(x==0)
{
w=1;
}
else
{
for(y=1;y<=x;y++)
{
w*=y;
}
}
printf( " w : %d \n", w );
z+=(float)1/w;
printf("%.9Lf\n",z);
}
printf("%.9Lf\n",z);
return 0;
}

Nov 8 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Randell D. | last post by:
I have just recompiled, upgraded to PHP 4.3.4. As an exercise (and curiosity) I've decided to test out PDF functions and got the test in the PHP online manual working. I had one problem whereby...
2
by: thecrow | last post by:
Alright, what the hell is going on here? In the following code, I expect the printed result to be: DEBUG: frank's last name is burns. Instead, what I get is: DEBUG: frank's last name is...
220
by: Brandon J. Van Every | last post by:
What's better about Ruby than Python? I'm sure there's something. What is it? This is not a troll. I'm language shopping and I want people's answers. I don't know beans about Ruby or have...
699
by: mike420 | last post by:
I think everyone who used Python will agree that its syntax is the best thing going for it. It is very readable and easy for everyone to learn. But, Python does not a have very good macro...
9
by: Martin Maney | last post by:
In my copious spare time I've been dabbling at getting a computerized version of a board game working. After deciding that tk just made me want to vomit, and wx was like swimming through...
92
by: Reed L. O'Brien | last post by:
I see rotor was removed for 2.4 and the docs say use an AES module provided separately... Is there a standard module that works alike or an AES module that works alike but with better encryption?...
3
by: Ron_Adam | last post by:
Ok... it's works! :) So what do you think? Look at the last stacked example, it process the preprocess's first in forward order, then does the postprocess's in reverse order. Which might be...
12
by: Dario | last post by:
The following simple program behaves differently in Windows and Linux . #include <stdexcept> #include <iostream> #include <string> using namespace std; class LogicError : public logic_error {...
30
by: James Conrad StJohn Foreman | last post by:
After 3 years of using DB2 on Linux, I'm leaving my current employers to go work for a SQL Server shop instead. In order to find my replacement, they're trying to put together a set of questions...
2
by: yogesh | last post by:
char TCGI::x2c(char *what) { register char digit; digit = (char) ((what >= 'A' ? ((what & 0xdf) - 'A')+10 : (what - '0'))); digit *= (char) 16; digit += (char) ((what >= 'A' ? ((what & 0xdf) -...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.