CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Hybrid View

  1. #1
    Join Date
    Jun 2012
    Posts
    1

    Question How to select the first n terms?

    Code:
    for(i=0;i<500;i++)
    {
        x=valuex[i];
        y=valuey[i];
    
        A[i][0]=x+y;
        A[i][1]=x*x+3*y;
        A[i][2]=x+2*y*x;
        ……
        A[i][99]=x/2+20*y;
    }
    In the above code,there are 100 terms:A[i][0]~A[i][100], In fact, I want to use the first n terms of A[i][j],and "n" is the input number by user, how can I realize this efficiently,Thank you for your help.
    Best wishes.

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: How to select the first n terms?

    Use std::vector instead of a plain array.
    Victor Nijegorodov

  3. #3
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: How to select the first n terms?

    You could certainly benefit from a second loop rather than hardcoding the indices. Use n as the loop condition to control the count.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured