Thread: One simple question

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Oct 2005
    Posts
    18

    One simple question

    Hi all,here i have one very simple program.I want to divide an interval [-1,1] into 10 sub intervals.so then i will have each of them devided by 10 more sub sub interval.You can get this from code easy though.What im asking is when its supposed to be zero it gives computer epsilon i.e 3,27826e-8 but it has to be zero.here is my code.what do i need to change this?
    output that i have is like this

    Code:
    interval -1 -0.8
    -1 -0.998 -0.996 - 0.994...........................-0.8
    ....
    ...
    interval -0.2 3,27826e-8
    -0.2 -0.198 - 0.196 -0.194.......................3,27826e-8
    Code:
    #include <iostream>
    
    using namespace std;
    
    int main()
    {
        
        float X[11],XSub[11];
        int i=0,j=0;
      
        X[0]=-1;    
        
        for (i=0;i<10;i++)
        {
            X[i+1]=X[i]-(- 0.2);  
            XSub[0]=X[i];
             
            cout<<"interval "<<X[i]<<" "<<X[i+1]<<endl;
            for (j=0;j<11;j++)
            {
               XSub[j+1]=XSub[j]-(-0.02) ;
               cout<<XSub[j]<<" ";
                
            }
            cout<<endl;             
       }
        
        cin.get();
        return 0;
    }
    Last edited by turkertopal; 10-14-2005 at 02:54 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Simple question regarding variables
    By Flakster in forum C++ Programming
    Replies: 10
    Last Post: 05-18-2005, 08:10 PM
  2. Simple class question
    By 99atlantic in forum C++ Programming
    Replies: 6
    Last Post: 04-20-2005, 11:41 PM
  3. Simple question about pausing program
    By Noid in forum C Programming
    Replies: 14
    Last Post: 04-02-2005, 09:46 AM
  4. simple question.
    By InvariantLoop in forum Windows Programming
    Replies: 4
    Last Post: 01-31-2005, 12:15 PM
  5. simple fgets question
    By theweirdo in forum C Programming
    Replies: 7
    Last Post: 01-27-2002, 06:58 PM