473,385 Members | 1,309 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,385 software developers and data experts.

#INF00 ocurrs when cal. sum=(n/2)*(2*a+(n-1)*d)

2
Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. int main()
  3. { float sum, n, a, d, l;
  4. n=l-a+1, d=1, a=1, l=100;
  5. sum=(n/2)*(2*a+(n-1)*d);  
  6. printf("The sum of the numbers from %f to %f is %f.", a, l, sum);
  7.  
  8.     fflush(stdin);
  9.     printf("\n\nPlease press Enter to continue......");
  10.     getchar ();
  11.     return 0;
  12. }

it is calculating 1+2+3+...+100=sum
why the sum becomes 1.#INF00???
PLZ HELP!!!!thz a LOT!!!
Sep 18 '07 #1
3 4382
sicarie
4,677 Expert Mod 4TB
Expand|Select|Wrap|Line Numbers
  1. n=l-a+1, d=1, a=1, l=100;
  2.  
In this line right here, when you set n, what are the values of l and a?
Sep 18 '07 #2
aryucc
2
In this line right here, when you set n, what are the values of l and a?
that means i have to do it like the followings:

Expand|Select|Wrap|Line Numbers
  1. { float sum, n, a, d, l;//n=no of term, a=first term, d=different, l=last term
  2. d=1, a=1, l=100, n=l-a+1;
  3. sum=(n/2)*(2*a+(n-1)*d);  
  4. printf("The sum of the numbers from %f to %f is %f.", a, l, sum);
right???

thz so much.
Sep 18 '07 #3
sicarie
4,677 Expert Mod 4TB
that means i have to do it like the followings:

Expand|Select|Wrap|Line Numbers
  1. { float sum, n, a, d, l;//n=no of term, a=first term, d=different, l=last term
  2. d=1, a=1, l=100, n=l-a+1;
  3. sum=(n/2)*(2*a+(n-1)*d);  
  4. printf("The sum of the numbers from %f to %f is %f.", a, l, sum);
right???

thz so much.
You might consider putting it on a separate line, just in case a compiler gets creative, but yes, you are not instantiating the values before you create them, which leads to undefined behavior.
Sep 18 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Nuno | last post by:
Is there any SQL Error? Or I have to use Select case in VB code to control SQL instead. Thank you for any ans. Nuno
13
by: elad | last post by:
Hi The Menu doesn't work properly when I have 2 frame and the Menu popup frame=document target frame, when I choose item in the menu the doc opened and the menu get stuck. Here is the code...
7
by: sql-db2-dba | last post by:
Does DB2 just fudge it when it is an empty table? Is there a "formula" for average row size when you have variable length records. Or you really have to know what your application is packing into...
4
by: Peter Row | last post by:
Hi, I have created a UserControl which is subsequently hosted on a standard form. My control has a TabControl on it but it has no TabPages configured. At runtime I create X pages and put a...
5
by: AAguiar | last post by:
I have an asp.net project where the code behind the aspx page calls a c# class which makes calls to a managed static C++ class. The C# class works fine when the asp net worker process starts, when...
1
by: juan blanco | last post by:
Hi all, I am trying to compile / rebuild a solution with msbuild to be part of our continuous integration. One of the projects aliases a referenced project to resolve confilicting namespaces....
22
by: Alexandre Proulx | last post by:
I am trying to find 2 at the power of 601, but my calculator doesn't have a large enough screen, so I decided to make a program for my computer to do this, but when I get to a high number the...
11
by: isaacrc82 | last post by:
Hi every body: An exception is thrown when I open some files in linux, this doesn't occurrs when I do the same in windows XP. This is the pierce of code that throws the exception: 42 ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.