Solved

Arithmetic inside arrays

Posted on 2008-10-21
2
220 Views
Last Modified: 2012-05-05
Why is is that when I create my array with this line:

      double b[6] = {1/6, 5/24, 11/120, 19/720, 29/5040, 1/840};

and then cout the contents using:

      for (Counter2 = 0; Counter2 < 6; Counter2++)
            cout << "b[" << Counter2 << "]: " << b[Counter2] << endl;

The resulting output is:

b[0]: 0
b[1]: 0
b[2]: 0
b[3]: 0
b[4]: 0
b[5]: 0
0
Comment
Question by:ltdanp22
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 45

Accepted Solution

by:
sunnycoder earned 500 total points
ID: 22765373
you are dividing integers and resulting integer (0) is then cast to double.
0
 
LVL 45

Assisted Solution

by:sunnycoder
sunnycoder earned 500 total points
ID: 22765382
#include <stdio.h>

int main ()
{
     double b[6] = {1.0/6, 5.0/24, 11.0/120, 19.0/720, 29.0/5040, 1.0/840};
     int i;
     for (i=0; i<6; i++)
    {
        printf("%f\n",b[i]);
    }
}
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
Navigation is an important part of web design from a usability perspective. But it is often a pain when it comes to a developer’s perspective. By navigation, it often means menuing. This is less theory and more practical of how to get a specific gro…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question