RSS Forums RSS
Please support our C++ advertiser: Programming Forums

stuck

Join Date: May 2008
Posts: 29
Reputation: wellibedamned is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
wellibedamned wellibedamned is offline Offline
Light Poster

stuck

  #1  
May 25th, 2008
could someone please check this code and tell me where i went wrong... it always gives the result 1.00000 but as you can see in the for loop it shouldn't be like that.
#include <cstdio>
int main(void)
{
    int n;
    float s = 0;
    scanf("%d", &n);
    for(int i = 1; i <= n; i++)
            {
            if(i % 2 == 0) s -= 1/(i*i);
            else s += 1/(i*i);    
            }            
    printf("%1.5f", s);
    scanf("\n");
    return 0;
}
AddThis Social Bookmark Button
Reply With Quote  
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 10:35 pm.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC